|
1 | | -import path from 'node:path'; |
2 | | -import { openReadonlyOrFail } from '../db/index.js'; |
| 1 | +import { openReadonlyOrFail, resolveDbConfig } from '../db/index.js'; |
3 | 2 | import { normalizeFileFilter } from '../db/query-builder.js'; |
4 | 3 | import { bfsTransitiveCallers } from '../domain/analysis/impact.js'; |
5 | 4 | import { explainData } from '../domain/queries.js'; |
6 | | -import { DEFAULTS, loadConfig } from '../infrastructure/config.js'; |
| 5 | +import { DEFAULTS } from '../infrastructure/config.js'; |
7 | 6 | import { debug } from '../infrastructure/logger.js'; |
8 | 7 | import { isTestFile } from '../infrastructure/test-filter.js'; |
9 | 8 | import { toErrorMessage } from '../shared/errors.js'; |
@@ -35,13 +34,7 @@ function resolveThresholds( |
35 | 34 | config: unknown, |
36 | 35 | ): Record<string, ThresholdEntry> { |
37 | 36 | try { |
38 | | - const cfg = |
39 | | - config || |
40 | | - (() => { |
41 | | - const dbDir = customDbPath ? path.dirname(customDbPath) : process.cwd(); |
42 | | - const repoRoot = path.resolve(dbDir, '..'); |
43 | | - return loadConfig(repoRoot); |
44 | | - })(); |
| 37 | + const cfg = config || resolveDbConfig(customDbPath); |
45 | 38 | const userRules = (cfg as Record<string, unknown>).manifesto || {}; |
46 | 39 | const resolved: Record<string, ThresholdEntry> = {}; |
47 | 40 | for (const def of FUNCTION_RULES) { |
@@ -144,7 +137,10 @@ export function auditData( |
144 | 137 | opts: AuditDataOpts = {}, |
145 | 138 | ): AuditResult { |
146 | 139 | const noTests = opts.noTests || false; |
147 | | - const config = opts.config || loadConfig(); |
| 140 | + // Derive rootDir from customDbPath (not process.cwd()) so `--db /other/repo/...` |
| 141 | + // reads that repo's .codegraphrc.json (issue #1881) — matches resolveThresholds() |
| 142 | + // below, which already derived rootDir correctly. |
| 143 | + const config = opts.config || resolveDbConfig(customDbPath); |
148 | 144 | const maxDepth = |
149 | 145 | opts.depth || |
150 | 146 | (config as unknown as { analysis?: { auditDepth?: number } }).analysis?.auditDepth || |
@@ -174,7 +170,7 @@ export function auditData( |
174 | 170 | customDbPath, |
175 | 171 | config.db?.busyTimeoutMs ?? DEFAULTS.db.busyTimeoutMs, |
176 | 172 | ); |
177 | | - const thresholds = resolveThresholds(customDbPath, opts.config); |
| 173 | + const thresholds = resolveThresholds(customDbPath, config); |
178 | 174 |
|
179 | 175 | let functions: AuditFunctionEntry[]; |
180 | 176 | try { |
|
0 commit comments