Skip to content

Commit 4f75c82

Browse files
committed
hunt: differential harness + round-2 findings — node core crash found & filed
Harness (hunt/) runs signature cases + 3000-pair reference-adjudicated fuzz against any equality lib. Round 2: found a NEW node core crash (TypeError on Maps with null keys, all three assert/util deep-equal APIs, v24+v26, 2-entry repro) -> filed nodejs/node#64433; es-toolkit Map dup-key false negatives deviating from lodash -> filed toss/es-toolkit#1881. remeda/@wry/react-fast-compare defects banked for next wave. deep-eql exonerated: coherent S1 semantics, zero fuzz defects — the one incumbent that earns respect. Engine and brute-force reference never disagreed across ~30k adjudications.
1 parent 3489976 commit 4f75c82

5 files changed

Lines changed: 331 additions & 9 deletions

File tree

‎PR-CAMPAIGN.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,22 @@ The "are we missing dequal functionality" question is answered empirically:
112112
2021 so patience or a gentle ping in a few weeks
113113
- [ ] Next targets when energy allows: Vitest opt-in matcher (research
114114
their iterableEquality first), TanStack replaceEqualDeep fuzz
115+
116+
## Hunt round 2 (2026-07-11, hunt/differential.mjs + hunt/round2.mjs)
117+
118+
Differential harness (signature cases + 3000-pair fuzz per lib, adjudicated
119+
by engine + brute-force reference — the two never split once):
120+
121+
| library | defects found | filed |
122+
|---|---|---|
123+
| **nodejs core** (util/assert deep equal) | **NEW CRASH**: TypeError on Maps with null keys (2-entry repro, v24+v26, all 3 APIs); plus the known ring false-negative | **nodejs/node#64433** (crash) |
124+
| **es-toolkit** isEqual | Map dup-shaped-key false negatives (~10% of equal collection pairs in fuzz); deviates from lodash | **toss/es-toolkit#1881** |
125+
| remeda isDeepEqual | RangeError on cycles; dup-key FN; boxed-primitive FALSE POSITIVE (new Number(1) ≡ new Number(2)); ~10% fuzz FN | next wave |
126+
| @wry/equality (Apollo) | ring FN; dup-key FN; 17% fuzz FN rate | next wave |
127+
| react-fast-compare | SILENT false on self-cycles (no crash — worse); ring FN; dup-key FN | next wave |
128+
| deep-eql (chai) | **EXONERATED**: zero fuzz defects; rings correct; C3+C3≡C6 is coherent unfolding (S1) semantics, not a bug. Strongest incumbent found. Do NOT file. | — |
129+
130+
Notes: Vitest's expect uses jasmine-derived equals, NOT deep-eql — still
131+
needs its own probe. The hunt harness lives in hunt/ and points at any lib
132+
in minutes; the "found bugs in node core" line is now a credibility asset
133+
for every future filing.

‎hunt/differential.mjs‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/* Defect hunt: run every candidate equality lib against the signature cases
2+
* and a differential fuzz adjudicated by isoequal + the brute-force
3+
* reference. Output: per-lib defect table for the PR campaign.
4+
* Run: node hunt/differential.mjs (from repo root, after npm run build) */
5+
import { isDeepStrictEqual } from 'node:util'
6+
import { createRequire } from 'node:module'
7+
import { isoEqual, isoEqualReference } from '../dist/index.js'
8+
9+
const require = createRequire(import.meta.url)
10+
11+
const libs = {}
12+
libs['node:isDeepStrictEqual'] = isDeepStrictEqual
13+
try { libs['deep-eql (chai/vitest)'] = require('deep-eql') } catch (e) { console.error('deep-eql load:', e.message) }
14+
try { libs['es-toolkit isEqual'] = require('es-toolkit').isEqual } catch (e) { console.error('es-toolkit load:', e.message) }
15+
try { libs['remeda isDeepEqual'] = require('remeda').isDeepEqual } catch (e) { console.error('remeda load:', e.message) }
16+
try { libs['@wry/equality (apollo)'] = require('@wry/equality').equal } catch (e) { console.error('wry load:', e.message) }
17+
try { libs['react-fast-compare'] = require('react-fast-compare') } catch (e) { console.error('rfc load:', e.message) }
18+
19+
/* ------------------------------ signature cases --------------------------- */
20+
const ring = (k) => {
21+
const nodes = Array.from({ length: k }, () => ({}))
22+
for (let i = 0; i < k; i++) nodes[i].next = nodes[(i + 1) % k]
23+
return nodes
24+
}
25+
const shuffledRingSet = (k, order) => {
26+
const b = ring(k)
27+
return new Set(order.map((i) => b[i]))
28+
}
29+
30+
const CASES = []
31+
{
32+
// 1. self-cycle (must be true)
33+
const a = {}; a.self = a
34+
const b = {}; b.self = b
35+
CASES.push(['self-cycle', a, b, true])
36+
}
37+
{
38+
// 2. cyclic shuffled rings in Sets (must be true)
39+
CASES.push(['C6 vs shuffled C6 in Set', new Set(ring(6)), shuffledRingSet(6, [3, 1, 5, 0, 4, 2]), true])
40+
}
41+
{
42+
// 3. C3+C3 vs C6 (must be false)
43+
CASES.push(['C3+C3 vs C6', new Set([...ring(3), ...ring(3)]), new Set(ring(6)), false])
44+
}
45+
{
46+
// 4. multiset trap (must be false)
47+
CASES.push(['set multiset trap', new Set([[1, 2], [1, 2], [3, 4]]), new Set([[1, 2], [3, 4], [3, 4]]), false])
48+
}
49+
{
50+
// 5. Map duplicate-shaped keys (must be true)
51+
CASES.push(['Map dup-shaped keys', new Map([[{}, 1], [{}, 2]]), new Map([[{}, 2], [{}, 1]]), true])
52+
}
53+
{
54+
// 6. nested-set false positive (dequal#31 shape; must be false)
55+
CASES.push(['nested-set overcount', new Set([new Set([1, 2]), new Set([1, 2])]), new Set([new Set([1, 2]), new Set([1, 4])]), false])
56+
}
57+
{
58+
// 7. boxed primitives (must be false)
59+
// eslint-disable-next-line no-new-wrappers
60+
CASES.push(['boxed Number 1 vs 2', new Number(1), new Number(2), false])
61+
}
62+
{
63+
// 8. plain agreement sanity (must be true)
64+
CASES.push(['plain nested equal', { a: [1, { b: 2 }], s: new Set([1, 2]) }, { a: [1, { b: 2 }], s: new Set([2, 1]) }, true])
65+
}
66+
67+
console.log('=== SIGNATURE CASES ===')
68+
const defects = {}
69+
for (const [name, fn] of Object.entries(libs)) {
70+
defects[name] = []
71+
for (const [label, a, b, want] of CASES) {
72+
let got
73+
try {
74+
got = fn(a, b)
75+
} catch (e) {
76+
got = `THROW(${e.constructor.name})`
77+
}
78+
const ok = got === want
79+
if (!ok) defects[name].push(`${label}: got ${got}, want ${want}`)
80+
}
81+
}
82+
for (const [name, list] of Object.entries(defects)) {
83+
console.log(`\n--- ${name}: ${list.length} defects`)
84+
for (const d of list) console.log(' ✗', d)
85+
}
86+
87+
/* ------------------------------ acyclic fuzz ------------------------------ */
88+
let s = 0xdecafbad
89+
const rnd = () => {
90+
s ^= s << 13; s ^= s >>> 17; s ^= s << 5
91+
return (s >>> 0) / 0x100000000
92+
}
93+
const ri = (n) => (rnd() * n) | 0
94+
const PRIMS = [0, 1, 'a', 'b', true, null, undefined]
95+
function gen(depth) {
96+
if (depth <= 0 || rnd() < 0.35) return PRIMS[ri(PRIMS.length)]
97+
const kind = ri(4)
98+
const n = 1 + ri(3)
99+
if (kind === 0) return Array.from({ length: n }, () => gen(depth - 1))
100+
if (kind === 1) {
101+
const o = {}
102+
for (let i = 0; i < n; i++) o[`k${ri(4)}`] = gen(depth - 1)
103+
return o
104+
}
105+
if (kind === 2) return new Set(Array.from({ length: n }, () => gen(depth - 1)))
106+
return new Map(Array.from({ length: n }, () => [gen(depth - 1), gen(depth - 1)]))
107+
}
108+
109+
console.log('\n=== ACYCLIC DIFFERENTIAL FUZZ (3000 pairs/lib) ===')
110+
for (const [name, fn] of Object.entries(libs)) {
111+
let falseNeg = 0
112+
let falsePos = 0
113+
let crash = 0
114+
let example = null
115+
for (let i = 0; i < 3000; i++) {
116+
const a = gen(3)
117+
const b = rnd() < 0.4 ? structuredClone(a) : gen(3)
118+
const truth = isoEqualReference(a, b) // exhaustive oracle
119+
if (isoEqual(a, b) !== truth) { console.log('!!! ENGINE/ORACLE SPLIT', i); break }
120+
let got
121+
try {
122+
got = fn(a, b)
123+
} catch {
124+
crash++
125+
continue
126+
}
127+
if (got !== truth) {
128+
if (truth && !got) falseNeg++
129+
else falsePos++
130+
if (!example) example = i
131+
}
132+
}
133+
console.log(`${name}: falseNeg=${falseNeg} falsePos=${falsePos} crash=${crash}${example !== null ? ` (first at i=${example})` : ''}`)
134+
}

‎hunt/round2.mjs‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* Round 2: (a) deep-eql deep fuzz (it survived signatures), (b) extract the
2+
* single node:isDeepStrictEqual crash from the acyclic corpus. */
3+
import deepEql from 'deep-eql'
4+
import { inspect } from 'node:util'
5+
import { isDeepStrictEqual } from 'node:util'
6+
import { isoEqual, isoEqualReference } from '../dist/index.js'
7+
8+
let s = 0xdecafbad
9+
const rnd = () => {
10+
s ^= s << 13; s ^= s >>> 17; s ^= s << 5
11+
return (s >>> 0) / 0x100000000
12+
}
13+
const ri = (n) => (rnd() * n) | 0
14+
const PRIMS = [0, 1, 'a', 'b', true, null, undefined]
15+
function gen(depth) {
16+
if (depth <= 0 || rnd() < 0.35) return PRIMS[ri(PRIMS.length)]
17+
const kind = ri(4)
18+
const n = 1 + ri(3)
19+
if (kind === 0) return Array.from({ length: n }, () => gen(depth - 1))
20+
if (kind === 1) {
21+
const o = {}
22+
for (let i = 0; i < n; i++) o[`k${ri(4)}`] = gen(depth - 1)
23+
return o
24+
}
25+
if (kind === 2) return new Set(Array.from({ length: n }, () => gen(depth - 1)))
26+
return new Map(Array.from({ length: n }, () => [gen(depth - 1), gen(depth - 1)]))
27+
}
28+
29+
/* (b) node crash extraction — same seed as round 1 */
30+
console.log('=== node crash extraction ===')
31+
for (let i = 0; i < 3000; i++) {
32+
const a = gen(3)
33+
const b = rnd() < 0.4 ? structuredClone(a) : gen(3)
34+
try {
35+
isDeepStrictEqual(a, b)
36+
} catch (e) {
37+
console.log(`node CRASHED at i=${i}: ${e.constructor.name}: ${e.message.slice(0, 120)}`)
38+
console.log('A =', inspect(a, { depth: 6, breakLength: 120 }))
39+
console.log('B =', inspect(b, { depth: 6, breakLength: 120 }))
40+
console.log('truth (reference):', isoEqualReference(a, b), '| isoequal:', isoEqual(a, b))
41+
}
42+
}
43+
44+
/* (a) deep-eql: acyclic differential + cyclic metamorphic */
45+
console.log('\n=== deep-eql acyclic differential (3000) ===')
46+
s = 0xdecafbad
47+
let fn = 0, fp = 0, crash = 0, firstFN = null, firstFP = null
48+
const savedFN = [], savedFP = []
49+
for (let i = 0; i < 3000; i++) {
50+
const a = gen(3)
51+
const b = rnd() < 0.4 ? structuredClone(a) : gen(3)
52+
const truth = isoEqualReference(a, b)
53+
let got
54+
try {
55+
got = deepEql(a, b)
56+
} catch { crash++; continue }
57+
if (got !== truth) {
58+
if (truth) { fn++; if (savedFN.length < 2) savedFN.push([a, b]) }
59+
else { fp++; if (savedFP.length < 2) savedFP.push([a, b]) }
60+
}
61+
}
62+
console.log(`deep-eql: falseNeg=${fn} falsePos=${fp} crash=${crash}`)
63+
for (const [a, b] of savedFN) {
64+
console.log('FN example A =', inspect(a, { depth: 6, breakLength: 120 }))
65+
console.log(' B =', inspect(b, { depth: 6, breakLength: 120 }))
66+
}
67+
for (const [a, b] of savedFP) {
68+
console.log('FP example A =', inspect(a, { depth: 6, breakLength: 120 }))
69+
console.log(' B =', inspect(b, { depth: 6, breakLength: 120 }))
70+
}
71+
72+
console.log('\n=== deep-eql cyclic metamorphic (shuffled clones must be equal) ===')
73+
const ring = (k) => {
74+
const nodes = Array.from({ length: k }, () => ({}))
75+
for (let i = 0; i < k; i++) nodes[i].next = nodes[(i + 1) % k]
76+
return nodes
77+
}
78+
let bad = 0
79+
for (let k = 3; k <= 8; k++) {
80+
const A = new Set(ring(k))
81+
const b = ring(k)
82+
// rotate + swap orders
83+
for (let rot = 0; rot < k; rot++) {
84+
const order = Array.from({ length: k }, (_, i) => (i + rot) % k)
85+
const B = new Set(order.map((i) => b[i]))
86+
if (!deepEql(A, B)) bad++
87+
}
88+
}
89+
console.log(`ring rotations wrong: ${bad}`)
90+
console.log('C3+C3 vs C6 (want false):', deepEql(new Set([...ring(3), ...ring(3)]), new Set(ring(6))))
91+
// mixed: cyclic elements + duplicate-shaped Maps in one Set
92+
const mkCyclicMapSet = () => {
93+
const parent = { id: 'p' }
94+
const child = { id: 'c', parent }
95+
parent.kids = new Set([child])
96+
return new Set([parent, new Map([[{}, 1], [{}, 2]])])
97+
}
98+
console.log('cyclic+dupkey combo (want true):', deepEql(mkCyclicMapSet(), mkCyclicMapSet()))

0 commit comments

Comments
 (0)