Skip to content

Commit 7caf0dd

Browse files
committed
fix: guard leiden-native-parity skip condition against stale native addon
hasNative only checked that the addon loaded, not that it exports leidenCommunities. A cached addon predating this binding would make assertParity silently degrade to a JS-vs-JS comparison, or runNativeDirect throw a confusing TypeError on its non-null assertion.
1 parent 306ce69 commit 7caf0dd

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

tests/graph/algorithms/leiden-native-parity.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import { louvainCommunities } from '../../../src/graph/algorithms/louvain.js';
2020
import { CodeGraph } from '../../../src/graph/model.js';
2121
import { getNative, isNativeAvailable } from '../../../src/infrastructure/native.js';
2222

23-
const hasNative = isNativeAvailable();
23+
// Guards against a stale/cached native addon that loads but predates the
24+
// `leidenCommunities` binding (#1804 review): without the export check,
25+
// assertParity would silently degrade to a JS-vs-JS comparison and
26+
// runNativeDirect's non-null assertion would throw a confusing TypeError.
27+
const hasNative = isNativeAvailable() && typeof getNative()?.leidenCommunities === 'function';
2428

2529
/** Sorted "node:community" pairs — stable snapshot for deep-equal comparison. */
2630
function snapshot(assignments: Map<string, number>): string[] {

0 commit comments

Comments
 (0)