Contract home directory paths in JSON/NDJSON output #475
+238
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contract home directory paths in JSON/NDJSON output
Summary
This PR makes JSON/NDJSON output consistent by contracting home directory paths to use tilde notation (
~/) across all commands (list,status,sync).Problem
JSON/NDJSON output had an inconsistency where
workspace_rootused tilde notation butpathused absolute paths:{ "name": "flask", "path": "/home/username/code/flask", // ❌ Absolute path "workspace_root": "~/code/" // ✅ Tilde notation }This created three issues:
Solution
Apply
contract_user_home()to allpathfields in JSON/NDJSON output:{ "name": "flask", "path": "~/code/flask", // ✅ Tilde notation "workspace_root": "~/code/" // ✅ Tilde notation }Changes
Modified path fields in:
vcspull list: Both flat and tree output modesvcspull status: Repository status outputvcspull sync: Both plan and sync event outputImportant: Human-readable output unchanged. Only JSON/NDJSON affected.
Benefits
~/in examples)Breaking Change Details
Impact
Automation that:
pathfields from JSON/NDJSON outputWill need to expand tildes to absolute paths before use.
Migration Guide
Most tools handle tilde expansion automatically. If needed:
Python:
Bash:
expanded_path="${path/#\~/$HOME}"JavaScript:
Test Coverage
Added 6 comprehensive parametrized tests using project's NamedTuple pattern:
tests/cli/test_list.pytest_list_repos_path_contractionwith 3 fixtures:tests/cli/test_status.pytest_status_repos_path_contractionwith 3 fixtures:All tests verify:
~/workspace_rootconsistency maintainedExamples
vcspull list --jsonBefore:
[ { "name": "tiktoken", "url": "git+https://github.com/openai/tiktoken.git", "path": "/home/d/study/ai/tiktoken", "workspace_root": "~/study/ai/" } ]After:
[ { "name": "tiktoken", "url": "git+https://github.com/openai/tiktoken.git", "path": "~/study/ai/tiktoken", "workspace_root": "~/study/ai/" } ]vcspull status --jsonBefore:
[ { "reason": "status", "name": "flask", "path": "/home/username/code/flask", "workspace_root": "~/code/", "exists": true } ]After:
[ { "reason": "status", "name": "flask", "path": "~/code/flask", "workspace_root": "~/code/", "exists": true } ]vcspull sync --dry-run --jsonBefore:
[ { "reason": "plan", "name": "flask", "path": "/home/username/code/flask", "workspace_root": "~/code/", "action": "clone" } ]After:
[ { "reason": "plan", "name": "flask", "path": "~/code/flask", "workspace_root": "~/code/", "action": "clone" } ]Implementation Details
Modified Functions
src/vcspull/cli/list.py(2 locations)src/vcspull/cli/status.py(1 location)src/vcspull/cli/sync.py(2 locations)Test Structure
Using project's NamedTuple parametrization pattern:
Documentation
Documentation already correct - examples in
docs/cli/*.mdwere updated in PR #473 to show tilde notation proactively. This PR makes the actual code behavior match what the docs promised.Testing
All 208 tests pass:
$ uv run pytest ============================= 208 passed in 4.79s ==============================Verified output:
Commits
4de9970- cli(feat[privacy]): Contract home paths in JSON/NDJSON output2c4e749- cli(test[privacy]): Add comprehensive tests for contracted JSON paths52da2d7- docs(CHANGES): Document path contraction as breaking change for v1.41.xChecklist