Skip to content

refactor(storage): centralize default_db_path in utils#70

Closed
syf2211 wants to merge 3 commits into
Wolfvin:mainfrom
syf2211:fix/default-db-path-dedup
Closed

refactor(storage): centralize default_db_path in utils#70
syf2211 wants to merge 3 commits into
Wolfvin:mainfrom
syf2211:fix/default-db-path-dedup

Conversation

@syf2211

@syf2211 syf2211 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Extract the duplicated _default_db_path() helper into a single utils.default_db_path() function and route PersistentRegistry through the same helper.

Motivation

_default_db_path() was copy-pasted identically in graph_schema.py and graph_model.py, and persistent_registry.py inlined the same path logic. Any future change (e.g. CODELENS_DB_PATH support) would need to be applied in multiple places, creating silent drift risk.

Fixes #40

Changes

  • Add DB_FILENAME and default_db_path() to scripts/utils.py
  • Remove local _default_db_path() from graph_schema.py and graph_model.py
  • Re-export default_db_path as _default_db_path from graph_model.py for backward compatibility with existing imports
  • Use default_db_path() in PersistentRegistry.__init__ and db_exists()
  • Add TestDefaultDbPath regression test asserting all three modules resolve the same path

Tests

  • pytest tests/test_graph_model.py::TestDefaultDbPath -v — PASS
  • pytest tests/test_graph_model.py -q — 21 passed

Notes

  • resolve_types.py still has a local copy; left out of scope to keep this PR minimal. Happy to follow up.
  • No behavior change: path format remains <workspace>/.codelens/codelens.db.

syf2211 added 3 commits June 28, 2026 11:33
Extract the duplicated _default_db_path helper from graph_schema.py and
graph_model.py into utils.default_db_path, and route PersistentRegistry
path construction through the same helper.

Fixes Wolfvin#40
Use os.path.abspath before joining the .codelens DB path so relative
or traversal workspace inputs cannot escape the intended directory.

Addresses SonarCloud security rating on PR Wolfvin#70.
Use pytest tmp_path instead of /tmp/codelens-workspace to satisfy
SonarCloud rule python:S5443 (publicly writable directories).

Addresses SonarCloud security rating on PR Wolfvin#70.
@Wolfvin

Wolfvin commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Review - Closing as superseded by #71

Thanks for the PR! Solid implementation, but PR #71 addresses the same issue (#40) with slightly better coverage, so closing this to avoid duplicate merge conflicts.

Why #71 wins

What this PR did better

  • tmp_path fixture for test cleanup (minor)
  • os.path.abspath(workspace) inside the helper (defensive against relative paths)

These are minor enough that #71 can adopt them in a follow-up if needed.

Verdict

Closing. Your contribution is appreciated - please feel free to pick up another open issue at https://github.com/Wolfvin/CodeLens/issues.

Reviewed by BOS (orchestrate-workers skill) - diff read in full before decision.

@Wolfvin Wolfvin closed this Jun 28, 2026
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants