Zero config bug finder for JavaScript and TypeScript
Find bugs in any JavaScript library automatically
Point breakhound at an npm package or a folder. It reads the types, tries edge cases on every exported function and hands you a reproduction and a Vitest test for each bug.
$npx breakhound ./my-lib
Paste and see
Paste two versions. See what broke.
Sniff runs both versions on the same edge case inputs, right here in your browser, and lists every input where the answers differ.
Old
New
sniff@agency: ~/compareready
Sniff compares the two versions as soon as the page is ready.
Runs in a worker in this tab, nothing is uploaded. Plain JavaScript, with optional types on the parameters to pick the inputs. For a whole package, the CLI compares the reports of two versions with --baseline.
Live terminal
Watch a real run, line by line
This is breakhound 1.1.0 hunting through test/fixtures/buggy-lib, a small library with planted bugs. Press Run, or type a command.
sniff@agency: ~/casesrecorded from v1.1.0
Sniff's terminal: a real run of breakhound1.1.0 on test/fixtures/buggy-lib,replayed line by line.Type a command and press Enter, or press Run.
Try
mainbuggy-lib@1.0.0seed 42ready
functions analyzed
23
calls in isolated processes
4,444
time zones per call
6
findings, each with a test
12
Procedure
From package name to failing test in one command
Everything below happens inside npx breakhound. You keep only the part you care about: the tests.
01
Read the types
breakhound installs the package with --ignore-scripts or opens your folder, then reads its TypeScript declarations to learn every exported function and parameter.
02
Bag the evidence
Each parameter gets values from edgegoat: DST transitions, dates before 1970, emoji, lone surrogates, -0 and NaN. Callbacks are generated too.
03
Interrogate in isolation
Every call runs in a child process with a timeout, repeated under several TZ values, with a fixed seed so the same command finds the same bugs.
04
File the report
Eight oracles judge the results. Each finding is shrunk to a minimal input and confirmed in a fresh process, then written up with a reproduction and a Vitest test.
Eight oracles
Every oracle is an open case file
An oracle is an invariant that almost every library should keep. Each file below is a real finding from the recorded run: the suspect function, the evidence that broke it, the verdict and the Vitest test breakhound wrote.
5 high, 5 medium, 2 info findings in the full report
Case 01lone-surrogate-output
Split emoji
A string result holds half of a surrogate pair, so an emoji is cut in two.
high
Suspect
truncate(text: string, max: number): string
Evidence
'\u{1F600}', 1
Findings
truncate('\u{1F600}', 1)'\ud83d'
Verdict
truncate returns a string with a lone surrogate. Expected: A well formed string. Cut text at code point or grapheme boundaries so surrogate pairs stay together.
Generated test confidence high
truncate.test.ts
import { expect, test } from 'vitest';import { truncate } from 'buggy-lib';const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;test("truncate returns well formed UTF-16", () => { const result = truncate('\u{1F600}', 1); expect(result).not.toMatch(LONE_SURROGATE);});
A value the types allow makes the engine throw a TypeError.
high
Suspect
initials(name: string): string
Evidence
''
Findings
initials('')throws TypeError: Cannot read properties of undefined (reading 'toUpperCase')
Verdict
initials throws TypeError: Cannot read properties of undefined (reading 'toUpperCase'). Expected: A return value, or an explicit error that explains which input is not supported (and a declared type that excludes it).
Generated test confidence high
initials.test.ts
import { expect, test } from 'vitest';import { initials } from 'buggy-lib';test("initials does not throw TypeError for valid input", () => { expect(() => initials('')).not.toThrow();});
Case 04nan-leak
NaN leak
Finite numbers go in and NaN comes out where a number was expected.
medium
Suspect
average(values: number[]): number
Evidence
[0]
Findings
average([0])NaN
Verdict
average returns NaN for finite input. Expected: A finite number, or an explicit error for inputs outside the supported range.
Generated test confidence high
average.test.ts
import { expect, test } from 'vitest';import { average } from 'buggy-lib';test("average does not return NaN for finite input", () => { expect(average([0])).not.toBeNaN();});
Case 05roundtrip
Broken roundtrip
A decode and encode pair does not give the input back.
medium
Suspect
encodeBase(text: string): string
Evidence
'_'
Findings
encodeBase('_')'_'
decodeBase(encodeBase('_'))' '
Verdict
decodeBase(encodeBase(x)) does not return x. Expected: decodeBase(encodeBase(x)) equals x.
Generated test confidence medium
encodeBase.test.ts
import { expect, test } from 'vitest';import { encodeBase, decodeBase } from 'buggy-lib';test("decodeBase reverses encodeBase", () => { const input = '_'; const encoded = encodeBase('_'); expect(decodeBase(encoded)).toEqual(input);});
Case 06not-idempotent
Not idempotent
Normalizing twice changes the result again.
medium
Suspect
slugify(text: string): string
Evidence
'x y'
Findings
slugify('x y')'x_y'
slugify(slugify('x y'))'x-y'
Verdict
slugify is not idempotent. Expected: slugify(slugify(x)) equals slugify(x).
Generated test confidence medium
slugify.test.ts
import { expect, test } from 'vitest';import { slugify } from 'buggy-lib';test("slugify is idempotent", () => { const once = slugify('x y'); expect(slugify(once)).toEqual(once);});
Case 07negative-zero-sign
Lost minus sign
Values between -1 and 0 are printed as if they were positive.
medium
Suspect
formatFixed(value: number): string
Evidence
-0.5
Findings
formatFixed(-0.5)'0.50'
formatFixed(0.5)'0.50'
formatFixed(-1.5)'-1.50'
Verdict
formatFixed drops the minus sign of numbers between -1 and 0. Expected: A result with a minus sign, like '-1.50' for -1.5.
Generated test confidence medium
formatFixed.test.ts
import { expect, test } from 'vitest';import { formatFixed } from 'buggy-lib';test("formatFixed keeps the sign of -0.5", () => { expect(formatFixed(-0.5)).not.toBe(formatFixed(0.5));});
Same call, same input, a different result from hidden state.
medium
Suspect
label(text: string): string
Evidence
'a'
Findings
label('a')'a'
label('a')'A'
Verdict
label returns different results for the same input. Expected: The same result for the same arguments, or a name and documentation that make the variation explicit.
Generated test confidence medium
label.test.ts
import { expect, test } from 'vitest';import { label } from 'buggy-lib';test("label is deterministic", () => { const first = label('a'); const second = label('a'); expect(second).toEqual(first);});
Evidence board
Every oracle traces back to a merged fix
breakhound is built by Alexandre Kohler, who has landed 130 merged bug fixes in projects at Google, Microsoft, GitHub, Mozilla, Vue and more. Hover a card to follow the string from a real pull request to the case it became.
Lead detective: Sniff
130merged bug fixes across open source. Each pattern became an oracle.
Add one step to GitHub Actions. --fail-on high fails the job on serious findings, and inside Actions breakhound writes annotations and a job summary on its own. This summary was produced by the same recorded run. Read the CI guide.
.github/workflows/breakhound.yml
name: breakhoundon: [push, pull_request]jobs: sniff: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 - run: npm ci --ignore-scripts # annotations and a job summary are written automatically - run: npx breakhound . --fail-on high
--fail-on high exits with code 1 when a high finding exists.
Each finding becomes an error, warning or notice annotation.
The job summary lists every finding with its reproduction and test.
high lone-surrogate-output: initials: initials returns a string with a lone surrogate
Every string argument is well formed UTF-16, but the return value contains an unpaired surrogate (U+D83D at index 0). A lone surrogate renders as a replacement character, makes encodeURIComponent throw and is changed by TextEncoder and by JSON round trips through UTF-8. It usually means a string was cut between the two halves of a surrogate pair, for example by slice, substring, substr or a length limit counted in UTF-16 code units.
Expected: A well formed string. Cut text at code point or grapheme boundaries so surrogate pairs stay together.
Minimal input: '\u{1F600}'
Confidence: high, confirmed in a fresh process
Reproduction:
Reproduction
// initials returns a string with a lone surrogate// Found by breakhound. Package: buggy-lib@1.0.0import { initials } from 'buggy-lib';const result = initials('\u{1F600}');console.log(result);// true means the string contains a lone surrogate (isWellFormed() is false on Node 20+):console.log(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(result));
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { initials } from 'buggy-lib';const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;test("initials returns well formed UTF-16", () => { const result = initials('\u{1F600}'); expect(result).not.toMatch(LONE_SURROGATE);});
high lone-surrogate-output: truncate: truncate returns a string with a lone surrogate
Every string argument is well formed UTF-16, but the return value contains an unpaired surrogate (U+D83D at index 0). A lone surrogate renders as a replacement character, makes encodeURIComponent throw and is changed by TextEncoder and by JSON round trips through UTF-8. It usually means a string was cut between the two halves of a surrogate pair, for example by slice, substring, substr or a length limit counted in UTF-16 code units.
Expected: A well formed string. Cut text at code point or grapheme boundaries so surrogate pairs stay together.
Minimal input: '\u{1F600}', 1
Confidence: high, confirmed in a fresh process
Reproduction:
Reproduction
// truncate returns a string with a lone surrogate// Found by breakhound. Package: buggy-lib@1.0.0import { truncate } from 'buggy-lib';const result = truncate('\u{1F600}', 1);console.log(result);// true means the string contains a lone surrogate (isWellFormed() is false on Node 20+):console.log(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(result));
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { truncate } from 'buggy-lib';const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;test("truncate returns well formed UTF-16", () => { const result = truncate('\u{1F600}', 1); expect(result).not.toMatch(LONE_SURROGATE);});
high timezone-dependent: yearLabel: yearLabel returns different results in different time zones
yearLabel takes no Date and no time zone argument, yet the same call returns a different value when the process runs with TZ=America/Sao_Paulo instead of TZ=UTC. Code like this usually mixes local time getters (getHours, getDate, getFullYear, toLocaleString) with UTC values, so results change near midnight and New Year, or between servers and browsers in different zones.
Expected: The same result in every time zone, or an explicit time zone parameter.
Minimal input: 0
Confidence: medium, confirmed in a fresh process
Reproduction:
Reproduction
// yearLabel returns different results in different time zones// Found by breakhound. Package: buggy-lib@1.0.0import { yearLabel } from 'buggy-lib';for (const tz of ['UTC', 'America/Sao_Paulo']) { process.env.TZ = tz; console.log(tz, yearLabel(0));}
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { yearLabel } from 'buggy-lib';test("yearLabel does not depend on the host time zone", () => { const original = process.env.TZ; try { process.env.TZ = 'UTC'; const expected = yearLabel(0); process.env.TZ = 'America/Sao_Paulo'; expect(yearLabel(0)).toEqual(expected); } finally { if (original === undefined) delete process.env.TZ; else process.env.TZ = original; }});
high unexpected-crash: initials: initials throws TypeError: Cannot read properties of undefined (reading 'toUpperCase')
The arguments match the declared parameter types (initials(name: string): string), but the call throws TypeError: Cannot read properties of undefined (reading 'toUpperCase'). This message comes from the JavaScript engine, not from an explicit validation check, which usually means the code reads a property of undefined or null, calls a missing method or iterates something that is not iterable.
Expected: A return value, or an explicit error that explains which input is not supported (and a declared type that excludes it).
Minimal input: ''
Confidence: high, confirmed in a fresh process
Reproduction:
Reproduction
// initials throws TypeError: Cannot read properties of undefined (reading 'toUpperCase')// Found by breakhound. Package: buggy-lib@1.0.0import { initials } from 'buggy-lib';console.log(initials(''));// TypeError: Cannot read properties of undefined (reading 'toUpperCase')
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { initials } from 'buggy-lib';test("initials does not throw TypeError for valid input", () => { expect(() => initials('')).not.toThrow();});
high unexpected-crash: mapWords: mapWords throws TypeError: Cannot read properties of undefined (reading 'toUpperCase')
The arguments match the declared parameter types (mapWords(text: string, fn: (word: string) => string): string), but the call throws TypeError: Cannot read properties of undefined (reading 'toUpperCase'). This message comes from the JavaScript engine, not from an explicit validation check, which usually means the code reads a property of undefined or null, calls a missing method or iterates something that is not iterable.
Expected: A return value, or an explicit error that explains which input is not supported (and a declared type that excludes it).
Minimal input: '', (word) => word
Confidence: high, confirmed in a fresh process
Reproduction:
Reproduction
// mapWords throws TypeError: Cannot read properties of undefined (reading 'toUpperCase')// Found by breakhound. Package: buggy-lib@1.0.0import { mapWords } from 'buggy-lib';console.log(mapWords('', (word) => word));// TypeError: Cannot read properties of undefined (reading 'toUpperCase')
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { mapWords } from 'buggy-lib';test("mapWords does not throw TypeError for valid input", () => { expect(() => mapWords('', (word) => word)).not.toThrow();});
medium nan-leak: average: average returns NaN for finite input
All numeric arguments are finite, but the result is NaN. NaN usually leaks from 0 / 0, Infinity - Infinity, arithmetic on undefined or a failed lookup, and then spreads silently through later calculations.
Expected: A finite number, or an explicit error for inputs outside the supported range.
Minimal input: [0]
Confidence: high, confirmed in a fresh process
Reproduction:
Reproduction
// average returns NaN for finite input// Found by breakhound. Package: buggy-lib@1.0.0import { average } from 'buggy-lib';console.log(average([0]));
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { average } from 'buggy-lib';test("average does not return NaN for finite input", () => { expect(average([0])).not.toBeNaN();});
medium nondeterministic: label: label returns different results for the same input
Calling label twice in a row with the same arguments, in the same process, gave different results. The clock is frozen during the calls and each call gets a fresh copy of the arguments, so the difference comes from somewhere else: Math.random, a module level counter or cache, or other state shared between calls.
Expected: The same result for the same arguments, or a name and documentation that make the variation explicit.
Minimal input: 'a'
Confidence: medium, confirmed in a fresh process
Reproduction:
Reproduction
// label returns different results for the same input// Found by breakhound. Package: buggy-lib@1.0.0import { label } from 'buggy-lib';const first = label('a');const second = label('a');console.log(first, second);
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { label } from 'buggy-lib';test("label is deterministic", () => { const first = label('a'); const second = label('a'); expect(second).toEqual(first);});
medium roundtrip: encodeBase: decodeBase(encodeBase(x)) does not return x
encodeBase and decodeBase look like inverse functions. For a well formed input x, decodeBase(encodeBase(x)) returned ' ' instead of x. One of the two functions loses information for this input, or the pair is not meant to be inverse (then this finding can be ignored).
Expected: decodeBase(encodeBase(x)) equals x.
Minimal input: '_'
Confidence: medium, confirmed in a fresh process
Reproduction:
Reproduction
// decodeBase(encodeBase(x)) does not return x// Found by breakhound. Package: buggy-lib@1.0.0import { encodeBase, decodeBase } from 'buggy-lib';const input = '_';const encoded = encodeBase('_');const decoded = decodeBase(encoded);console.log(encoded, decoded);
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { encodeBase, decodeBase } from 'buggy-lib';test("decodeBase reverses encodeBase", () => { const input = '_'; const encoded = encodeBase('_'); expect(decodeBase(encoded)).toEqual(input);});
medium not-idempotent: slugify: slugify is not idempotent
The name suggests a normalizing function, and applying a normalizer twice should change nothing. For this input a second application changed the result again ('x_y' became 'x-y'), so values normalized once and values normalized twice compare as different.
Expected: slugify(slugify(x)) equals slugify(x).
Minimal input: 'x y'
Confidence: medium, confirmed in a fresh process
Reproduction:
Reproduction
// slugify is not idempotent// Found by breakhound. Package: buggy-lib@1.0.0import { slugify } from 'buggy-lib';const once = slugify('x y');const twice = slugify(once);console.log(once, twice);
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { slugify } from 'buggy-lib';test("slugify is idempotent", () => { const once = slugify('x y'); expect(slugify(once)).toEqual(once);});
medium negative-zero-sign: formatFixed: formatFixed drops the minus sign of numbers between -1 and 0
formatFixed(-0.5) returns '0.50', the same as for 0.5. Negative numbers outside that range keep their sign (formatFixed(-1.5) returns '-1.50'), so the sign is lost only when the integer part is zero. This often happens when the integer part is computed first and the sign is read from it: the integer part of -0.5 is -0, which prints as "0".
Expected: A result with a minus sign, like '-1.50' for -1.5.
Minimal input: -0.5
Confidence: medium, confirmed in a fresh process
Reproduction:
Reproduction
// formatFixed drops the minus sign of numbers between -1 and 0// Found by breakhound. Package: buggy-lib@1.0.0import { formatFixed } from 'buggy-lib';console.log(formatFixed(-0.5));console.log(formatFixed(0.5));console.log(formatFixed(-1.5));
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { formatFixed } from 'buggy-lib';test("formatFixed keeps the sign of -0.5", () => { expect(formatFixed(-0.5)).not.toBe(formatFixed(0.5));});
info unexpected-crash: percent: percent throws RangeError for some inputs that match its types
For arguments that match the declared types (percent(part: number, total: number): number), the call throws RangeError: total must not be 0. This looks like an intentional validation error or a documented limit, so it is reported for information only. If the input is not supported, a narrower declared type would let TypeScript users catch it at compile time.
Expected: A narrower declared type, or a documented error.
Minimal input: 0, 0
Confidence: high
Reproduction:
Reproduction
// percent throws RangeError for some inputs that match its types// Found by breakhound. Package: buggy-lib@1.0.0import { percent } from 'buggy-lib';console.log(percent(0, 0));// RangeError: total must not be 0
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { percent } from 'buggy-lib';test("percent accepts this input", () => { expect(() => percent(0, 0)).not.toThrow();});
info nondeterministic: randomToken: randomToken returns a different result on each call
randomToken returned different results for the same arguments. Its name suggests randomness, time or unique ids, so this is likely intended.
Expected: The same result for the same arguments, or a name and documentation that make the variation explicit.
Minimal input: (no arguments)
Confidence: high
Reproduction:
Reproduction
// randomToken returns a different result on each call// Found by breakhound. Package: buggy-lib@1.0.0import { randomToken } from 'buggy-lib';const first = randomToken();const second = randomToken();console.log(first, second);
Vitest test:
Vitest test
import { expect, test } from 'vitest';import { randomToken } from 'buggy-lib';test("randomToken is deterministic", () => { const first = randomToken(); const second = randomToken(); expect(second).toEqual(first);});
Skipped signatures (1)
Counter: class (constructors are not called)
errorbreakhound lone-surrogate-output
initials initials returns a string with a lone surrogate with input '\u{1F600}'
errorbreakhound lone-surrogate-output
truncate truncate returns a string with a lone surrogate with input '\u{1F600}', 1
errorbreakhound timezone-dependent
yearLabel yearLabel returns different results in different time zones with input 0
errorbreakhound unexpected-crash
initials initials throws TypeError: Cannot read properties of undefined (reading 'toUpperCase') with input ''
errorbreakhound unexpected-crash
mapWords mapWords throws TypeError: Cannot read properties of undefined (reading 'toUpperCase') with input '', (word) => word
warningbreakhound nan-leak
average average returns NaN for finite input with input [0]
warningbreakhound nondeterministic
label label returns different results for the same input with input 'a'
warningbreakhound roundtrip
encodeBase decodeBase(encodeBase(x)) does not return x with input '_'
warningbreakhound not-idempotent
slugify slugify is not idempotent with input 'x y'
warningbreakhound negative-zero-sign
formatFixed formatFixed drops the minus sign of numbers between -1 and 0 with input -0.5
noticebreakhound unexpected-crash
percent percent throws RangeError for some inputs that match its types with input 0, 0
noticebreakhound nondeterministic
randomToken randomToken returns a different result on each call with input (no arguments)
sniff
$ npx breakhound . --fail-on highbreakhound v1.1.0 buggy-lib@1.0.0 (local)23 functions analyzed, 1 skipped | 4444 calls | 6 time zones | seed 42HIGH (5) [lone-surrogate-output] initials returns a string with a lone surrogate [lone-surrogate-output] truncate returns a string with a lone surrogate [timezone-dependent] yearLabel returns different results in different time zones [unexpected-crash] initials throws TypeError [unexpected-crash] mapWords throws TypeErrorMEDIUM (5) ...Summary: 5 high, 5 medium, 0 low, 2 infoError: Process completed with exit code 1.
Interrogation
Questions, answered on the record
Q1What does breakhound need from my library?
TypeScript declarations: bundled .d.ts files or a package from DefinitelyTyped. They tell breakhound which functions are exported and what each parameter accepts. A package without declarations is reported with a clear message instead of being guessed at.
Q2Do I have to write tests or properties first?
No. breakhound ships a fixed set of invariants that hold for most libraries and derives the inputs from the type signatures. When it finds something, it hands you a regular Vitest test you can keep.
Q3Is it safe to run on any package?
breakhound executes the code it scans, so treat it like running the package's own test suite. Installs use --ignore-scripts and every call runs in a child process with a timeout, which is isolation for robustness, not a security sandbox. Scan untrusted packages inside a container or a disposable VM.
Q4How do I compare two versions?
Save a report for the old version with --json --output old.json, then run the new one with --baseline old.json. breakhound lists the findings that are new and the ones that were fixed, and --fail-on counts only the new ones. The demo at the top of this page compares the answers of two versions of one function.
Q5Will it report false positives?
Some invariants, such as time zone dependence, can be intentional for a given function. Every finding has a confidence level and a minimal reproduction so you can judge it in seconds, and --rules, --only and --exclude narrow the hunt.
Let Sniff work your library
One command, no config, no tests to write. You get the bugs, the reproductions and the Vitest tests.