fix(db): derive rootDir from customDbPath for engine config in openRepo/openReadonlyWithNative#1606
Merged
Merged
Conversation
…openReadonlyWithNative When a caller passes customDbPath pointing to a different repo, both openRepo() and openReadonlyWithNative() previously resolved the engine from process.env.CODEGRAPH_ENGINE (process-wide). They now derive the rootDir from the customDbPath convention (<rootDir>/.codegraph/graph.db) and call loadConfig(rootDir) to pick up that repo's build.engine setting. CODEGRAPH_ENGINE env still wins because applyEnvOverrides() overwrites config.build.engine when the env var is set, and opts.engine still takes explicit precedence in openRepo(). Closes #1605
Contributor
| const engine = opts.engine || process.env.CODEGRAPH_ENGINE || 'auto'; | ||
| // Derive rootDir from customDbPath so loadConfig reads the right project config. | ||
| // Convention: customDbPath = <rootDir>/.codegraph/graph.db | ||
| const rootDir = customDbPath ? path.dirname(path.dirname(path.resolve(customDbPath))) : undefined; |
Contributor
There was a problem hiding this comment.
Hardcoded 2-level ascent assumes default
dbPath depth
path.dirname(path.dirname(...)) works when customDbPath follows the default <rootDir>/.codegraph/graph.db convention (2 levels deep). If a project has overridden build.dbPath to a shallower or deeper relative path (e.g. "graph.db" at root, or "data/db/graph.db" 3 levels deep), the derived rootDir will point to the wrong directory. loadConfig would then silently return defaults (or even pick up an unrelated config), causing the wrong engine to be selected for that repo. The same pattern appears in openReadonlyWithNative at line 432.
Contributor
Codegraph Impact Analysis2 functions changed → 36 callers affected across 27 files
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
openRepo()andopenReadonlyWithNative()previously resolved the engine fromprocess.env.CODEGRAPH_ENGINEdirectly — a process-wide value that ignores the target repo's.codegraphrc.jsonwhencustomDbPathpoints to a different repo.rootDirfromcustomDbPathusing the established convention (<rootDir>/.codegraph/graph.db) and callloadConfig(rootDir)to getconfig.build.enginefor that repo.CODEGRAPH_ENGINEenv still wins becauseapplyEnvOverrides()already overwritesconfig.build.enginewhen the env var is set.opts.engine(explicit CLI flag) still takes precedence inopenRepo()via??.Test plan
npm test: 3120 tests, 185 files)npm run lint)Closes #1605