fix: derive loadConfig() rootDir from --db path in read-only query functions#2018
Conversation
…nctions manifestoData, hybridSearchData, moduleBoundariesData, diffImpactData, complexityData, and auditData called loadConfig() bare or with process.cwd(), so `--db /other/repo/.codegraph/graph.db` invoked from a different directory read the invoking directory's .codegraphrc.json instead of the target repo's. Export a new resolveConfigForDbPath() helper from db/connection.ts, generalizing the private deriveRootDirFromDbPath() added in #1763, and use it at all six call sites named in #1881. resolveDbSettings() and resolveBusyTimeoutMs() now delegate to it too, so rootDir derivation lives in exactly one place. Also fixes a latent bug in audit.ts's manual rootDir computation, which broke for directory-style --db inputs (findDbPath's directory normalization was bypassed).
Greptile SummaryThis PR fixes a cross-repo config resolution bug where six read-only query functions (
Confidence Score: 4/5The core bug fix is correct and well-tested; the only issue is a redundant The centralised helper is implemented correctly, all six call sites are updated, and the new tests prove config resolution comes from the src/features/audit.ts — the Important Files Changed
|
Codegraph Impact Analysis11 functions changed → 128 callers affected across 80 files
|
Summary
manifestoData(),hybridSearchData(),moduleBoundariesData(),diffImpactData(),complexityData()(viaresolveComplexityQueryOptions()), andauditData()each calledloadConfig()bare or withprocess.cwd()instead of deriving the rootDir from the resolved--dbpath. This meant--db /other/repo/.codegraph/graph.dbinvoked from a different working directory read the invoking directory's.codegraphrc.jsoninstead of the target repo's — silently applying the wrong manifesto thresholds, analysis depths, search settings, cohesion thresholds, anddb.busyTimeoutMs.auditData()'s file was internally inconsistent: its ownresolveThresholds()helper already derived rootDir correctly fromcustomDbPath, whileauditData()itself did not — and evenresolveThresholds()'s manualpath.dirname(customDbPath)+path.resolve(dbDir, '..')computation had a latent bug of its own, silently producing the wrong root when--dbpointed at a directory (e.g.--db /repoor--db /repo/.codegraph) rather than a file, because it skippedfindDbPath()'s directory-to-graph.dbnormalization.Fix
Generalized the private
deriveRootDirFromDbPath()helper (added in #1763) into a new exportedresolveConfigForDbPath(customDbPath?: string): CodegraphConfiginsrc/db/connection.ts(re-exported fromsrc/db/index.ts), and switched all six call sites named in #1881 to use it instead of duplicating the rootDir derivation ad hoc.resolveDbSettings()andresolveBusyTimeoutMs()now delegate to the same helper internally, so there is exactly one place that derives rootDir from a DB path.This is a pure TypeScript fix — the native Rust engine has no equivalent config-loading concept (
loadConfig()/.codegraphrc.jsonresolution only exists on the JS side), so no mirrored Rust change is needed.Closes #1881
Out of scope
While grepping for every
loadConfig()call site, I found the same bug pattern in several more functions not named in #1881's scope (triageData,sequenceData,communitiesData,briefData,statsData,searchData/multiSearchData, and the sharedresolveAnalysisOpts()used byfn-impact/exports/context). Filed as #2017 rather than fixed here, to keep this PR to the six call sites #1881 explicitly scoped.Test plan
npx tsc --noEmit/npm run build— cleannpm run lint— clean on all touched filestests/unit/loadconfig-dbpath-resolution.test.ts— unit testsresolveConfigForDbPath()directly (file-style and directory-style--dbpaths, no---dbfallback, missing-config fallback) plus one regression test per fixed call site, each mockingprocess.cwd()to an unrelated directory and asserting the configureddb.busyTimeoutMsstill reachesPRAGMA busy_timeout— proving resolution came from--db, not cwdtests/unit/busy-timeout-query-sites.test.ts(from db.busyTimeoutMs: extend config-driven wiring to read-only query paths and Rust connection.rs #1763): themanifestoData/hybridSearchDatatests previously had to mockprocess.cwd()to make the config visible at all — now they mock cwd to an unrelated dir with no config, proving the bug is fixednpm test— full suite: 3512 passed, 0 new failures. The only failures (22 tests across 18 files, all undertests/integration/) are pre-existing native-engine unavailability (Cannot find module '@optave/codegraph-darwin-arm64') in this worktree — a missing prebuilt native binary unrelated to this change (confirmed no file overlap with this diff, and the module is absent fromnode_modulesrepo-wide, not something introduced by this branch)codegraph diff-impact --staged -Tconfirmed the blast radius matches exactly the 6 targeted functions (plusresolveDbSettings/resolveBusyTimeoutMs, refactored to delegate to the new helper with no behavior change) and their existing callers — no unintended scope creep