Summary
The helper function _default_db_path(workspace) is defined identically in two modules:
scripts/commands/graph_schema.py:29-31
scripts/graph_model.py:161-163
Both return os.path.join(workspace, ".codelens", "codelens.db"). This is a classic copy-paste duplication that will drift the moment one site is updated (e.g., to respect a CODELENS_DB_PATH env var) and the other isn't.
Evidence
scripts/commands/graph_schema.py:29-31:
def _default_db_path(workspace: str) -> str:
# Return the default SQLite database path for the workspace.
return os.path.join(workspace, ".codelens", "codelens.db")
scripts/graph_model.py:161-163:
def _default_db_path(workspace: str) -> str:
# Return the default SQLite database path for the workspace.
return os.path.join(workspace, ".codelens", "codelens.db")
Identical docstring, identical body, identical signature.
Impact
- Drift risk: Any future change to the default path (e.g., adding
CODELENS_DB_PATH env var support, or moving the db out of .codelens/) must be made in both places. Forgetting one creates a silent bug where graph-schema and graph_model queries hit different databases.
- Three sources of truth actually:
PersistentRegistry also hardcodes DB_FILENAME = "codelens.db" (L36) and constructs its own path. So the "default db path" logic is triplicated, not just duplicated.
- Code smell: Easy to fix, but it discourages contributors from touching the storage layer.
Suggested fix
- Extract to a shared helper in
scripts/utils.py (or a new scripts/storage_paths.py):
# scripts/utils.py
def default_db_path(workspace: str) -> str:
# Return the default SQLite database path for the workspace.
return os.path.join(workspace, ".codelens", "codelens.db")
-
Replace all three sites:
scripts/commands/graph_schema.py: from utils import default_db_path (delete local def).
scripts/graph_model.py: same.
scripts/persistent_registry.py: replace DB_FILENAME + path-construction logic with a call to default_db_path(workspace) (keep DB_FILENAME only if it's used as a module-level constant elsewhere).
-
Add a test that asserts all three call sites produce the same path for the same workspace.
Files
scripts/commands/graph_schema.py (L29-31)
scripts/graph_model.py (L161-163)
scripts/persistent_registry.py (L36, _db_path construction in __init__)
scripts/utils.py (new default_db_path helper)
tests/test_graph_model.py (new path-consistency test)
Summary
The helper function
_default_db_path(workspace)is defined identically in two modules:scripts/commands/graph_schema.py:29-31scripts/graph_model.py:161-163Both return
os.path.join(workspace, ".codelens", "codelens.db"). This is a classic copy-paste duplication that will drift the moment one site is updated (e.g., to respect aCODELENS_DB_PATHenv var) and the other isn't.Evidence
scripts/commands/graph_schema.py:29-31:scripts/graph_model.py:161-163:Identical docstring, identical body, identical signature.
Impact
CODELENS_DB_PATHenv var support, or moving the db out of.codelens/) must be made in both places. Forgetting one creates a silent bug wheregraph-schemaandgraph_modelqueries hit different databases.PersistentRegistryalso hardcodesDB_FILENAME = "codelens.db"(L36) and constructs its own path. So the "default db path" logic is triplicated, not just duplicated.Suggested fix
scripts/utils.py(or a newscripts/storage_paths.py):Replace all three sites:
scripts/commands/graph_schema.py:from utils import default_db_path(delete local def).scripts/graph_model.py: same.scripts/persistent_registry.py: replaceDB_FILENAME+ path-construction logic with a call todefault_db_path(workspace)(keepDB_FILENAMEonly if it's used as a module-level constant elsewhere).Add a test that asserts all three call sites produce the same path for the same workspace.
Files
scripts/commands/graph_schema.py(L29-31)scripts/graph_model.py(L161-163)scripts/persistent_registry.py(L36,_db_pathconstruction in__init__)scripts/utils.py(newdefault_db_pathhelper)tests/test_graph_model.py(new path-consistency test)