Skip to content

[BUG-10] _default_db_path() duplicated in graph_schema.py and graph_model.py — divergence risk #40

Description

@Wolfvin

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

  1. 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.
  2. 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.
  3. Code smell: Easy to fix, but it discourages contributors from touching the storage layer.

Suggested fix

  1. 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")
  1. 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).
  2. 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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions