refactor(miner): extract shared local SQLite store helper - #4523
Conversation
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Extract the ~15 lines of path-resolution/permission/busy-timeout boilerplate hand-duplicated across run-state.js, claim-ledger.js, portfolio-queue.js, and event-ledger.js into a shared local-store.js (resolveLocalStoreDbPath / normalizeLocalStoreDbPath / openLocalStoreDb). Each store keeps its own file, table, and env var, and public APIs and on-disk layout are unchanged — this is a DRY pass, not a merge. As a side effect of routing through the shared open helper, run-state.js now also sets PRAGMA busy_timeout (the one inconsistency among the four stores), matching the other three's wait-don't-fail behavior under concurrent access. Add a "Local storage" README section documenting all four stores together (file, table, module, env var), and record the decision that the manage-status PR portfolio stays a read-time join for now rather than a dedicated table. Closes JSONbored#4272
a081a75 to
d03ea0b
Compare
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ Gittensory review result - approve/merge recommendedReview updated: 2026-07-09 23:08:59 UTC
✅ Suggested Action - Approve/Merge
Review summary Nits — 4 non-blocking
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4523 +/- ##
=======================================
Coverage 94.04% 94.04%
=======================================
Files 422 422
Lines 37574 37574
Branches 13724 13724
=======================================
Hits 35335 35335
Misses 1583 1583
Partials 656 656 🚀 New features to boost your workflow:
|
Summary
(Supersedes the original content of this PR — #4261 was independently solved by merged #4504 before this PR landed, so this branch was reset to
mainand repointed at a fresh, unblockedgittensor:priorityitem: #4272.)run-state.js,claim-ledger.js,portfolio-queue.js, andevent-ledger.jseach hand-duplicated the same ~15 lines of boilerplate: env-var/config-dir/XDG path resolution,mkdirSync(0o700)+chmodSync(0o600), andPRAGMA busy_timeout. This extracts that into a sharedlocal-store.js(resolveLocalStoreDbPath/normalizeLocalStoreDbPath/openLocalStoreDb):.sqlite3file, table, and env var — this is a DRY pass only, not a merge into one database. Public APIs and on-disk file layout are unchanged.run-state.jsnow also setsPRAGMA busy_timeout— the one inconsistency the audit found among the four stores — matching the other three's wait-don't-fail behavior under concurrent access.manage statusPR-portfolio view stays a read-time join (portfolio-queue.js+event-ledger.js'smanage_pr_updateevents) for now rather than becoming a dedicated table.Closes #4272
Test plan
test/unit/miner-local-store.test.ts— path resolution, path normalization/rejection,openLocalStoreDbpermissions + busy-timeout pragma (default and custom),:memory:skip path, and a regression test confirming all four stores still resolve to independent files with no accidental table mergetest/unit/miner-local-store-readme.test.ts— README documents all four stores + the PR-portfolio decisionresolveXDbPath/invalid_x_db_pathbehavior preserved)claim claim,claim list,state set,state get, andledger listagainst a cleanGITTENSORY_MINER_CONFIG_DIR, confirmed independent0600filesnpm run typechecknpm run test:ci(full local gate, green)