Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
2b6a00d
fix: scope codegraph batch complexity targets to file paths
carlos-alm Jul 5, 2026
b28051a
fix: exclude parameters and interface/type members from dead-role cla…
carlos-alm Jul 5, 2026
17fbcba
fix: credit import-type usages as exports consumers
carlos-alm Jul 5, 2026
26918bb
fix: prevent fn-impact/query crash when -f/--file is passed
carlos-alm Jul 5, 2026
be6432c
fix: correct exported-symbol detection for literal and object-literal…
carlos-alm Jul 5, 2026
4ead840
fix: exclude primitive type keywords from ast --kind string matching
carlos-alm Jul 5, 2026
f6326bf
fix: resolve call edges through renamed import specifiers
carlos-alm Jul 5, 2026
590f560
fix: couple file_hashes updates with edge regeneration in incremental…
carlos-alm Jul 5, 2026
d3ea4a4
fix: compare signature-change diffs using new-file line ranges
carlos-alm Jul 5, 2026
c306812
feat: add environment doctor check for stale native binary and missin…
carlos-alm Jul 5, 2026
8bb5893
fix: eliminate non-deterministic ordering in community detection
carlos-alm Jul 6, 2026
46037b1
fix: sync update-graph.sh hook extension allowlist with EXTENSIONS
carlos-alm Jul 6, 2026
6a84cf9
fix: recompute directory structure metrics for affected directories o…
carlos-alm Jul 6, 2026
8d936d1
refactor: register hardcoded execFileSync/execSync maxBuffer values i…
carlos-alm Jul 6, 2026
11c84be
fix: gate blast-radius check on newly introduced risk, not pre-existi…
carlos-alm Jul 6, 2026
963301a
fix: gate identifier-argument dynamic call edges on callback-acceptin…
carlos-alm Jul 6, 2026
3e8035d
fix: gate Array.from's callback arg by position, not just callee name
carlos-alm Jul 6, 2026
879635e
fix: scope reexportedSymbols to actually-named re-export specifiers
carlos-alm Jul 6, 2026
0fe9fc3
fix: stop CFG block/edge count from overriding AST-derived cyclomatic…
carlos-alm Jul 6, 2026
ccf3c19
fix: backfill edges.technique for incrementally-inserted calls edges
carlos-alm Jul 6, 2026
d5b1162
fix: wrap remote embedding JSON parse failure in EngineError
carlos-alm Jul 6, 2026
8971017
refactor: extract shared platform-default-path helper in config.ts
carlos-alm Jul 6, 2026
056c5e4
refactor: decompose loadConfig and related high-effort functions in c…
carlos-alm Jul 6, 2026
0738171
refactor: decompose findDbPath and openRepo in db/connection.ts (docs…
carlos-alm Jul 6, 2026
6f2423c
refactor: dedupe busy/locked error detection into isBusyOrLockedError
carlos-alm Jul 6, 2026
4c02378
fix: log statSync failures in findDbPath instead of silently swallowi…
carlos-alm Jul 6, 2026
0698e16
test: add direct unit coverage for closeDbPair/closeDbPairDeferred/cl…
carlos-alm Jul 6, 2026
4ac3b99
fix: correct blast-radius/fn-impact computation for line-shifted decl…
carlos-alm Jul 6, 2026
6767f09
feat: wire points-to solver max-iterations cap through DEFAULTS.analy…
carlos-alm Jul 6, 2026
5f6f30a
refactor: route console.log calls in domain/search through logger
carlos-alm Jul 6, 2026
b479318
refactor: reduce cyclomatic complexity of computeDeltaModularityDirected
carlos-alm Jul 6, 2026
c39ac40
refactor: unify impact-level rendering format between audit and fn-im…
carlos-alm Jul 6, 2026
067674f
refactor: dedupe computeSavings via pct helper and persist partial to…
carlos-alm Jul 6, 2026
f6807b4
fix: add main.rs driver to rust dynamic tracer fixture
carlos-alm Jul 6, 2026
1c07a54
fix: scope diff file-header detection to between-hunk positions
carlos-alm Jul 6, 2026
bf82aa2
fix: update titan-grind's dead-symbol script for current roles --json…
carlos-alm Jul 6, 2026
cd02d27
fix: thread configured busyTimeoutMs through remaining read-only quer…
carlos-alm Jul 6, 2026
980b5dc
fix: resolve computed string-literal keys in object-literal extractio…
carlos-alm Jul 6, 2026
4a873a3
fix: add same-class bare-call fallback to incremental rebuild path (d…
carlos-alm Jul 6, 2026
8f3348a
fix: unify Object.defineProperty accessor fallback kind-filtering bet…
carlos-alm Jul 6, 2026
acf804c
refactor: share chunked statement-cache primitive between builder and…
carlos-alm Jul 6, 2026
986c851
refactor: cache prepared statements in applyEdgeTechniquesAfterNative…
carlos-alm Jul 6, 2026
71e9174
fix: replace fixed-depth directory-proximity check with symmetric dis…
carlos-alm Jul 6, 2026
d2935cc
refactor: remove unreachable Partition delta-computation interface me…
carlos-alm Jul 6, 2026
6515186
fix: emit reference edges for function identifiers used as object-lit…
carlos-alm Jul 6, 2026
30c491a
refactor: unify call-ref and tests rendering format between audit and…
carlos-alm Jul 6, 2026
9db911b
fix: classify destructured bindings as constant, not function (docs c…
carlos-alm Jul 6, 2026
70559fc
refactor: adopt timeMedian in remaining benchmark timing loops
carlos-alm Jul 6, 2026
822e0eb
refactor: decompose runPerfBenchmarks in token-benchmark.ts
carlos-alm Jul 6, 2026
fcdfe7d
fix: attribute liveness to Lua functions assigned to global/builtin i…
carlos-alm Jul 6, 2026
ee6362c
refactor: extract shared sedi() helper for tracer scripts
carlos-alm Jul 6, 2026
d4e6212
fix: restore reflection dynamicKind for .call/.apply/.bind (docs chec…
carlos-alm Jul 6, 2026
aec5d2b
fix: restrict entry-role classification to function/method-kind symbo…
carlos-alm Jul 6, 2026
d250f8d
fix: credit destructured dynamic import() bindings as exports consumers
carlos-alm Jul 6, 2026
75978e2
fix: recognize Lua function nodes in complexity metrics computation (…
carlos-alm Jul 6, 2026
af17b6d
fix: scope global call-resolution fallback to same-language candidate…
carlos-alm Jul 6, 2026
dd447bc
fix: credit instanceof ClassName checks as exports consumers
carlos-alm Jul 6, 2026
a79a8a1
fix: update automated-review workflow to use current claude-code-acti…
carlos-alm Jul 6, 2026
d84f6b5
refactor: widen outputResult signature, remove redundant casts at cal…
carlos-alm Jul 6, 2026
e7a2255
fix: port Leiden algorithm to native Rust for cross-engine community-…
carlos-alm Jul 7, 2026
b54972a
feat: detect exported-symbol loss from full file deletion in checkNoS…
carlos-alm Jul 7, 2026
1821a8b
fix(complexity): scope summary stats to file/target/kind filters
carlos-alm Jul 7, 2026
d45aba7
fix(extractors): label property_signature interface/type members as k…
carlos-alm Jul 7, 2026
69d8a6f
fix(roles): exclude genuine class/struct properties from dead-role cl…
carlos-alm Jul 7, 2026
db08219
fix(resolver): scope extends/implements edges to same-file/import/lan…
carlos-alm Jul 7, 2026
79cd761
fix: track inline per-specifier type-only import modifier
carlos-alm Jul 7, 2026
cbfa954
fix(native): widen NativeRepository file filters to accept string[]
carlos-alm Jul 7, 2026
c0e7eae
fix(native): remove unused source param from get_first_call_arg
carlos-alm Jul 7, 2026
2dabe21
fix(extractors): align native/WASM definitions order for object-liter…
carlos-alm Jul 7, 2026
b1eb9af
fix(extractors): capture top-level const definitions regardless of in…
carlos-alm Jul 7, 2026
4a1e279
fix: exclude PHP scalar type-hint/cast keywords from ast --kind string
carlos-alm Jul 7, 2026
40b5e24
fix: track barrel re-export renames (export { X as Y } from ...)
carlos-alm Jul 7, 2026
1506896
fix: record local alias for dynamic import() destructuring renames
carlos-alm Jul 7, 2026
2dfd6bc
fix: resolve renamed-import receiver calls in qualified-method lookup
carlos-alm Jul 7, 2026
ccea0cb
fix(native): propagate edge/node write failures out of run_pipeline
carlos-alm Jul 7, 2026
93ccfa3
fix(exports): discriminate file-level from symbol-level consumer entries
carlos-alm Jul 7, 2026
e105c26
docs: refresh CONTRIBUTING.md for TypeScript architecture and current…
carlos-alm Jul 7, 2026
5d99bf0
fix(exports): credit plain imports of TypeScript interfaces/type aliases
carlos-alm Jul 7, 2026
e0ab9dc
fix(hooks): point update-graph.sh fallback build path at dist/cli.js
carlos-alm Jul 7, 2026
730b49b
fix(hooks): resolve track-edits.sh's PROJECT_DIR from the edited file…
carlos-alm Jul 7, 2026
0d7e8e6
fix: capture removed files' cross-directory neighbors before purge
carlos-alm Jul 7, 2026
c5b9a34
docs: fix stale codegraph check flag names in recommended-practices.md
carlos-alm Jul 7, 2026
2de6550
fix(cycles): classify cycles whose only closing edges are speculative
carlos-alm Jul 7, 2026
e5fe754
fix(resolver): recognize identifier args to user-defined higher-order…
carlos-alm Jul 8, 2026
4eef28e
fix(native): scope barrel-only import skipping to transient barrel re…
carlos-alm Jul 8, 2026
4090355
refactor(ast-analysis): extract shared CFG/complexity result-merging …
carlos-alm Jul 8, 2026
bf8e969
fix(incremental): port CHA/RTA dispatch, points-to, and dynamic-sink …
carlos-alm Jul 8, 2026
51b9e23
fix(config): derive ENV_LLM_KEYS from ENV_LLM_MAP to prevent drift
carlos-alm Jul 8, 2026
a62bab7
fix(resolver): resolveByGlobal picks the single best match, not every…
carlos-alm Jul 8, 2026
8f52d28
fix(embed): resolve default DB path from positional dir, not cwd
carlos-alm Jul 8, 2026
59220a5
refactor(leiden): extract makePartition's inline getters to cut cyclo…
carlos-alm Jul 8, 2026
2e1aa11
docs: regenerate stale audit/diff-impact example output blocks
carlos-alm Jul 8, 2026
3d436ca
fix(rust): resolve self.field, unit-struct, and constructor-typed locals
carlos-alm Jul 8, 2026
668451c
docs: add missing titan-grind mirror to claude-code-skills examples
carlos-alm Jul 8, 2026
4bccd4b
fix(scripts): migrate ts-resolve-loader.js off deprecated module.regi…
carlos-alm Jul 8, 2026
25ba42f
fix(native): recover renamed import names in the FFI hybrid import-ed…
carlos-alm Jul 8, 2026
431c0e5
fix: reconnect reverse-dep edges correctly when a sibling group's siz…
carlos-alm Jul 8, 2026
ab6a685
fix: derive loadConfig() rootDir from --db path in read-only query fu…
carlos-alm Jul 8, 2026
17e265b
fix(native): thread config.db.busyTimeoutMs into NativeDatabase open …
carlos-alm Jul 8, 2026
fdedff8
fix(extractors): unwrap computed string-literal keys in typeMap/proto…
carlos-alm Jul 8, 2026
6ef1731
fix(native): add Object.defineProperty accessor dispatch post-pass to…
carlos-alm Jul 8, 2026
afca17f
fix(resolver): kind-filter same-file bare-name lookup for receiver-be…
carlos-alm Jul 8, 2026
801d290
fix(resolver): attribute new ClassName() calls to the constructor method
carlos-alm Jul 8, 2026
a45e74d
fix(extractors): attribute same-file ES6 getter/setter property reads…
carlos-alm Jul 8, 2026
453a768
fix(resolver): require invocation evidence for object-literal value-r…
carlos-alm Jul 8, 2026
1d957a4
fix(extractors): resolve inline object-literal dispatch tables on WASM
carlos-alm Jul 8, 2026
438f2da
fix(extractors): emit per-element definitions for array-pattern destr…
carlos-alm Jul 8, 2026
0a07066
fix(scripts): resolve benchmark hub targets to a single, kind-filtere…
carlos-alm Jul 8, 2026
c43ab69
fix: resolve merge conflicts with main (docs check acknowledged)
carlos-alm Jul 11, 2026
d299cf9
fix: port PINNED_HUB_CANDIDATES to benchmark.ts for stable hub identi…
carlos-alm Jul 11, 2026
b78916a
docs: clarify HubTargets.mid is informational-only, not benchmarked (…
carlos-alm Jul 11, 2026
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
22 changes: 2 additions & 20 deletions scripts/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import fs from 'node:fs';
import path from 'node:path';
import { performance } from 'node:perf_hooks';
import { fileURLToPath } from 'node:url';
import Database from 'better-sqlite3';
import { resolveBenchmarkExcludes, resolveBenchmarkSource, srcImport } from './lib/bench-config.js';
import { isWorker, workerEngine, workerTargets, forkEngines } from './lib/fork-engine.js';
import { round1, timeMedian, timeMedianWithValue } from './lib/bench-timing.js';
import { PINNED_HUB_CANDIDATES, selectHubTargets } from './lib/hub-selection.js';

// ── Parent process: fork one child per engine, assemble final output ─────
if (!isWorker()) {
Expand Down Expand Up @@ -98,24 +98,6 @@ const QUERY_WARMUP_RUNS = 3;
const PROBE_FILE = path.join(root, 'src', 'domain', 'queries.ts');
const BENCH_EXCLUDE = [...resolveBenchmarkExcludes()];

function selectTargets() {
const db = new Database(dbPath, { readonly: true });
const rows = db
.prepare(
`SELECT n.name, COUNT(e.id) AS cnt
FROM nodes n
JOIN edges e ON e.source_id = n.id OR e.target_id = n.id
WHERE n.file NOT LIKE '%test%' AND n.file NOT LIKE '%spec%'
GROUP BY n.id
ORDER BY cnt DESC`,
)
.all();
db.close();

if (rows.length === 0) return { hub: 'buildGraph', leaf: 'median' };
return { hub: rows[0].name, leaf: rows[rows.length - 1].name };
}

// Redirect console.log to stderr so only JSON goes to stdout
const origLog = console.log;
console.log = (...args) => console.error(...args);
Expand Down Expand Up @@ -191,7 +173,7 @@ try {

// ── Query benchmarks ────────────────────────────────────────────────
console.error(` [${engine}] Benchmarking queries...`);
const targets = workerTargets() || selectTargets();
const targets = workerTargets() || selectHubTargets(dbPath, PINNED_HUB_CANDIDATES);
console.error(` hub=${targets.hub}, leaf=${targets.leaf}`);

async function benchQuery(fn, ...args) {
Expand Down
133 changes: 133 additions & 0 deletions scripts/lib/hub-selection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**
* Deterministic hub/mid/leaf target selection for benchmark scripts.
*
* `query-benchmark.ts` and `benchmark.ts` each pick representative call-graph
* nodes ("hub" = well-connected, "mid"/"leaf" = less connected) by `name` to
* drive their timed queries. Both independently duplicated a `selectTargets`
* query that filtered candidates by file path (`NOT LIKE '%test%'`/`'%spec%'`)
* but not by `kind` — so a hub-candidate name like `buildGraph` could resolve
* to a local `const { buildGraph } = await import(...)` binding (`kind =
* 'constant'`) instead of the real `function buildGraph` definition, and
* which node won depended on unspecified SQLite row order (#1904).
*
* This module is the single source of truth for that selection: it filters
* to `HUB_CANDIDATE_KINDS` (mirroring `CALLABLE_SYMBOL_KINDS` in
* `src/shared/kinds.ts`, #1888 — the same "same-name lookup with no other
* signal" hazard) and adds an explicit `ORDER BY id` tie-break so the choice
* is reproducible across builds that insert the same logical nodes in a
* different physical row order (e.g. worker-thread parse completion order).
*
* Callers that need to act on the resolved hub's file (e.g. `benchDiffImpact`
* writing a probe comment into it) should use the `hubFile` this returns
* instead of re-querying `nodes` by name — a second unfiltered query can
* disagree with this one about which physical node "the hub" is.
*/

import Database from 'better-sqlite3';

// Symbol kinds that represent a real invocable definition. Local variable
// and constant bindings must never win hub selection just because they share
// a candidate's name — mirrors CALLABLE_SYMBOL_KINDS in src/shared/kinds.ts.
export const HUB_CANDIDATE_KINDS: readonly string[] = ['function', 'method'];

// Pinned hub targets — stable function names expected to exist across
// versions. Auto-selecting the most-connected node makes version-to-version
// comparison meaningless whenever the most-connected function changes (e.g.
// a barrel/type file gets added or removed, or a new heavily-called utility
// shifts the ranking) — pinning keeps "the hub" identity stable so
// back-to-back benchmark runs measure the same node. Shared by both
// query-benchmark.ts and benchmark.ts so the two scripts can't drift apart
// on which names they consider stable.
export const PINNED_HUB_CANDIDATES: readonly string[] = ['buildGraph', 'openDb', 'loadConfig'];

export interface HubTargets {
hub: string;
hubFile: string;
/**
* Node at the median edge-count rank among kind-filtered candidates.
* Informational only: it is recorded in benchmark output for visibility
* but neither `query-benchmark.ts` nor `benchmark.ts` currently passes it
* into a `benchDepths`/`benchQuery` call, so it drives no timed
* measurement. See #2089 to wire it into an actual measurement or drop it.
*/
mid: string;
leaf: string;
}

interface NodeRow {
name: string;
file: string;
}

interface RankedNodeRow extends NodeRow {
cnt: number;
}

/**
* Selects stable, deterministic hub/mid/leaf targets from a freshly-built
* graph DB at `dbPath`.
*
* `pinnedCandidates` are tried in order (each filtered to
* `HUB_CANDIDATE_KINDS` and non-test files) before falling back to the
* most-connected qualifying node — pinning keeps the "hub" identity stable
* across versions where auto-selection would otherwise drift as files are
* added or removed.
*
* Throws if the graph has no qualifying nodes with edges at all (an empty or
* malformed build), rather than silently returning a name that resolves to
* nothing downstream.
*/
export function selectHubTargets(dbPath: string, pinnedCandidates: readonly string[] = []): HubTargets {
const db = new Database(dbPath, { readonly: true });
try {
const kindPlaceholders = HUB_CANDIDATE_KINDS.map(() => '?').join(', ');

let hub: string | null = null;
let hubFile: string | null = null;
for (const candidate of pinnedCandidates) {
const row = db
.prepare(
`SELECT n.name, n.file FROM nodes n
JOIN edges e ON e.source_id = n.id OR e.target_id = n.id
WHERE n.name = ? AND n.kind IN (${kindPlaceholders})
AND n.file NOT LIKE '%test%' AND n.file NOT LIKE '%spec%'
ORDER BY n.id ASC
LIMIT 1`,
)
.get(candidate, ...HUB_CANDIDATE_KINDS) as NodeRow | undefined;
if (row) {
hub = row.name;
hubFile = row.file;
break;
}
}

const rows = db
.prepare(
`SELECT n.id, n.name, n.file, COUNT(e.id) AS cnt
FROM nodes n
JOIN edges e ON e.source_id = n.id OR e.target_id = n.id
WHERE n.kind IN (${kindPlaceholders})
AND n.file NOT LIKE '%test%' AND n.file NOT LIKE '%spec%'
GROUP BY n.id
ORDER BY cnt DESC, n.id ASC`,
)
.all(...HUB_CANDIDATE_KINDS) as RankedNodeRow[];

if (rows.length === 0) {
throw new Error('No nodes with edges found in graph');
}

if (!hub) {
hub = rows[0].name;
hubFile = rows[0].file;
}

const mid = rows[Math.floor(rows.length / 2)].name;
const leaf = rows[rows.length - 1].name;
Comment on lines +126 to +127

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 mid is computed and exported but consumed nowhere

mid is included in HubTargets and tested, but neither query-benchmark.ts nor benchmark.ts ever passes targets.mid to a benchDepths/benchQuery call. It flows into the output JSON blob (as part of targets) but drives no actual measurement. If the intent is to benchmark medium-connectivity nodes, the corresponding benchDepths(fnDepsData, targets.mid, ...) calls are missing; if it's purely informational, the HubTargets interface and tests create the impression of an active selection that does not actually feed any benchmark.

Fix in Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Checked the history: this is pre-existing — the original (pre-extraction) selectTargets() in query-benchmark.ts computed mid and only ever logged it, never fed it into a benchDepths/benchQuery call, and this PR's own commit (0a07066) preserved that behavior unchanged while fixing the kind-filter/determinism bug (#1904). Actually wiring mid into a real measurement is a distinct feature change (new benchmark dimension, new output-JSON field, and potentially a new Pre-publish-benchmark-gate baseline entry) rather than a determinism fix, so I've kept it scope-bound to documentation here: added a doc comment directly on HubTargets.mid making the informational-only status explicit (commit b78916a), and opened #2089 to track wiring it into an actual measurement (or dropping it) as a follow-up.


return { hub, hubFile: hubFile as string, mid, leaf };
} finally {
db.close();
}
}
82 changes: 14 additions & 68 deletions scripts/query-benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import fs from 'node:fs';
import path from 'node:path';
import { performance } from 'node:perf_hooks';
import { fileURLToPath } from 'node:url';
import Database from 'better-sqlite3';
import { resolveBenchmarkExcludes, resolveBenchmarkSource, srcImport } from './lib/bench-config.js';
import { isWorker, workerEngine, workerTargets, forkEngines } from './lib/fork-engine.js';
import { round1, timeMedian } from './lib/bench-timing.js';
import { PINNED_HUB_CANDIDATES, selectHubTargets, type HubTargets } from './lib/hub-selection.js';

// ── Parent process: fork one child per engine, assemble final output ─────
if (!isWorker()) {
Expand Down Expand Up @@ -118,57 +118,6 @@ const RUNS = 5;
// before timing so the metric reflects warm-call latency, not cold-start.
const WARMUP_RUNS = 3;

// Pinned hub targets — stable function names that exist across versions.
// Auto-selecting the most-connected node makes version-to-version comparison
// meaningless when barrel/type files get added or removed.
const PINNED_HUB_CANDIDATES = ['buildGraph', 'openDb', 'loadConfig'];

function selectTargets() {
const db = new Database(dbPath, { readonly: true });
try {

// Try pinned candidates first for a stable hub across versions
let hub = null;
for (const candidate of PINNED_HUB_CANDIDATES) {
const row = db
.prepare(
`SELECT n.name FROM nodes n
JOIN edges e ON e.source_id = n.id OR e.target_id = n.id
WHERE n.name = ? AND n.file NOT LIKE '%test%' AND n.file NOT LIKE '%spec%'
LIMIT 1`,
)
.get(candidate);
if (row) {
hub = row.name;
break;
}
}

const rows = db
.prepare(
`SELECT n.name, COUNT(e.id) AS cnt
FROM nodes n
JOIN edges e ON e.source_id = n.id OR e.target_id = n.id
WHERE n.file NOT LIKE '%test%' AND n.file NOT LIKE '%spec%'
GROUP BY n.id
ORDER BY cnt DESC`,
)
.all();

if (rows.length === 0) throw new Error('No nodes with edges found in graph');

// Fall back to most-connected if no pinned candidate found
if (!hub) hub = rows[0].name;

const mid = rows[Math.floor(rows.length / 2)].name;
const leaf = rows[rows.length - 1].name;
return { hub, mid, leaf };

} finally {
db.close();
}
}

async function benchDepths(fn, name, depths) {
const result = {};
for (const depth of depths) {
Expand Down Expand Up @@ -197,21 +146,18 @@ function resolveDbFile(rootDir: string, dbFile: string): string | null {
return null;
}

async function benchDiffImpact(hubName) {
const db = new Database(dbPath, { readonly: true });
const row = db
.prepare(`SELECT file FROM nodes WHERE name = ? LIMIT 1`)
.get(hubName);
db.close();

if (!row) return { latencyMs: 0, affectedFunctions: 0, affectedFiles: 0 };

// row.file is normally relative (e.g. 'src/domain/builder.ts'), but some
// environments store absolute-like paths without the leading '/'. Handle
// both cases so the benchmark works regardless of DB path format.
const hubFile = resolveDbFile(root, row.file);
async function benchDiffImpact(targets: HubTargets) {
// Reuse the exact physical node selectHubTargets already resolved for
// `targets.hub` instead of re-querying `nodes` by name — a second,
// independently unfiltered query can disagree with the first about which
// same-named node "the hub" is (#1904).
//
// targets.hubFile is normally relative (e.g. 'src/domain/builder.ts'), but
// some environments store absolute-like paths without the leading '/'.
// Handle both cases so the benchmark works regardless of DB path format.
const hubFile = resolveDbFile(root, targets.hubFile);
if (!hubFile) {
console.error(`[benchDiffImpact] Cannot find hub file for row.file=${row.file}`);
console.error(`[benchDiffImpact] Cannot find hub file for hubFile=${targets.hubFile}`);
return { latencyMs: 0, affectedFunctions: 0, affectedFiles: 0 };
}
const original = fs.readFileSync(hubFile, 'utf8');
Expand Down Expand Up @@ -242,7 +188,7 @@ async function benchDiffImpact(hubName) {
if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath);
await buildGraph(root, { engine, incremental: false, exclude: [...resolveBenchmarkExcludes()] });

const targets = workerTargets() || selectTargets();
const targets: HubTargets = workerTargets() || selectHubTargets(dbPath, PINNED_HUB_CANDIDATES);
console.error(`Targets: hub=${targets.hub}, mid=${targets.mid}, leaf=${targets.leaf}`);

const fnDeps = {};
Expand All @@ -256,7 +202,7 @@ fnImpact.depth1Ms = (await benchDepths(fnImpactData, targets.hub, [1])).depth1Ms
fnImpact.depth3Ms = (await benchDepths(fnImpactData, targets.hub, [3])).depth3Ms;
fnImpact.depth5Ms = (await benchDepths(fnImpactData, targets.hub, [5])).depth5Ms;

const diffImpact = await benchDiffImpact(targets.hub);
const diffImpact = await benchDiffImpact(targets);

// Restore console.log for JSON output
console.log = origLog;
Expand Down
Loading
Loading