Skip to content

refactor(common): extract resolve_data_dir helper from get_db_path#729

Open
geoffjay wants to merge 2 commits intomainfrom
issue-722
Open

refactor(common): extract resolve_data_dir helper from get_db_path#729
geoffjay wants to merge 2 commits intomainfrom
issue-722

Conversation

@geoffjay
Copy link
Copy Markdown
Owner

refactor(common): extract resolve_data_dir helper from get_db_path

refactor(common): extract resolve_data_dir helper from get_db_path (closes #722)

@geoffjay geoffjay added the review-agent Used to invoke a review by an agent tracking this label label Mar 23, 2026
@geoffjay
Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 55.66%. Comparing base (a5867f0) to head (d9f2e1d).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
crates/common/src/storage.rs 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #729   +/-   ##
=======================================
  Coverage   55.66%   55.66%           
=======================================
  Files         126      126           
  Lines       13759    13762    +3     
=======================================
+ Hits         7659     7661    +2     
- Misses       6100     6101    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@geoffjay
Copy link
Copy Markdown
Owner Author

👀 Conductor: Awaiting Reviewer

PR #729 (refactor(common): extract resolve_data_dir helper) has CI passing and is in the review-agent queue awaiting a reviewer pickup.

Nudge posted by conductor pipeline sync.

Copy link
Copy Markdown
Owner Author

@geoffjay geoffjay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: refactor(common): extract resolve_data_dir helper from get_db_path

Stack position: issue-722 is directly on main with no parent PR
dependency, but git-spice reports (needs restack) — the branch is behind
main and must be rebased before the conductor can merge it.

The extraction of resolve_data_dir is the right refactor — sharing the
AGENTD_ENV-based path resolution between get_db_path and future callers
is clearly valuable. Two issues need fixing before this can merge.


Blocking — test race condition

The PR adds four separate #[test] functions that each mutate
std::env::var("AGENTD_ENV") via set_var / remove_var:

#[test]
fn test_resolve_data_dir_development() { ... }
#[test]
fn test_resolve_data_dir_dev_shorthand() { ... }
#[test]
fn test_resolve_data_dir_test() { ... }
#[test]
fn test_resolve_data_dir_production_contains_project_name() { ... }

These will race against each other and against the existing
test_get_db_path_respects_agentd_env when cargo test runs them in
parallel (the default). The result is non-deterministic test failures.

The comment directly above these tests says:

// All AGENTD_ENV variants are exercised in a single test to prevent
// data races between parallel test threads that share the process
// environment.

The implementation contradicts that comment. The existing
test_get_db_path_respects_agentd_env test in this file demonstrates the
correct pattern: exercise all AGENTD_ENV variants sequentially inside a
single #[test] function so only one test holds the env-var mutation at a
time.

Fix: collapse the four new tests into a single
test_resolve_data_dir_respects_agentd_env function that sequences all
variants, following the same structure as test_get_db_path_respects_agentd_env.


Non-blocking — doc comment displacement

The original get_db_path doc comment (lines 23–40 in the current file)
describes db_filename, mentions create_dir_all, and gives macOS/Linux
path examples. After this PR the extracted comment will be attached to
the private resolve_data_dir function, leaving the public get_db_path
with no doc comment at all.

Suggestion: keep a condensed doc comment on get_db_path describing its
public contract (what it returns, when it errors), and let resolve_data_dir
have a brief internal note. The full path examples are more useful on the
public function.


Action required before merge

  1. Fix the four separate env-var tests → single sequential test (blocking)
  2. Rebase onto main:
git-spice branch restack
git-spice branch submit

@geoffjay geoffjay added needs-rework PR has review feedback that must be addressed before merging needs-restack Branch is behind its stack parent, needs git-spice restack and removed review-agent Used to invoke a review by an agent tracking this label labels Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-restack Branch is behind its stack parent, needs git-spice restack needs-rework PR has review feedback that must be addressed before merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(common): extract environment-based path selection from get_db_path

1 participant