Skip to content

Conversation

@tony
Copy link
Member

@tony tony commented Oct 19, 2025

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).

⚠️ Breaking Change: Automation consuming JSON/NDJSON output may need updates.

Problem

JSON/NDJSON output had an inconsistency where workspace_root used tilde notation but path used absolute paths:

{
  "name": "flask",
  "path": "/home/username/code/flask",     // ❌ Absolute path
  "workspace_root": "~/code/"               // ✅ Tilde notation
}

This created three issues:

  1. Inconsistency: Same type of data (filesystem paths) represented differently
  2. Privacy: Exposes usernames in JSON output
  3. Portability: Absolute paths don't work when configs are shared between machines

Solution

Apply contract_user_home() to all path fields 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 modes
  • vcspull status: Repository status output
  • vcspull sync: Both plan and sync event output

Important: Human-readable output unchanged. Only JSON/NDJSON affected.

Benefits

  1. Consistency: All path fields now use the same notation
  2. Privacy: No username exposure in JSON output
  3. Portability: Configs and output work across different machines/users
  4. Alignment: Code behavior now matches documentation (which already showed ~/ in examples)

Breaking Change Details

Impact

Automation that:

  • Parses path fields from JSON/NDJSON output
  • Expects absolute paths
  • Doesn't handle tilde expansion

Will need to expand tildes to absolute paths before use.

Migration Guide

Most tools handle tilde expansion automatically. If needed:

Python:

import pathlib
expanded = pathlib.Path(path).expanduser()

Bash:

expanded_path="${path/#\~/$HOME}"

JavaScript:

const expanded = path.replace(/^~/, process.env.HOME);

Test Coverage

Added 6 comprehensive parametrized tests using project's NamedTuple pattern:

tests/cli/test_list.py

  • test_list_repos_path_contraction with 3 fixtures:
    • JSON output path contraction
    • NDJSON output path contraction
    • Tree mode JSON path contraction

tests/cli/test_status.py

  • test_status_repos_path_contraction with 3 fixtures:
    • JSON output path contraction
    • NDJSON output path contraction
    • Detailed mode JSON path contraction

All tests verify:

  • Paths start with ~/
  • Paths don't contain absolute home directory
  • workspace_root consistency maintained

Examples

vcspull list --json

Before:

[
  {
    "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 --json

Before:

[
  {
    "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 --json

Before:

[
  {
    "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

  1. src/vcspull/cli/list.py (2 locations)

    • Line 169: Flat output mode
    • Line 220: Tree output mode
  2. src/vcspull/cli/status.py (1 location)

    • Line 266: Status output
  3. src/vcspull/cli/sync.py (2 locations)

    • Line 267: Plan entry creation
    • Line 727: Sync event output

Test Structure

Using project's NamedTuple parametrization pattern:

class PathContractionFixture(t.NamedTuple):
    test_id: str
    output_json: bool
    output_ndjson: bool
    tree: bool

PATH_CONTRACTION_FIXTURES: list[PathContractionFixture] = [
    PathContractionFixture(
        test_id="json-output-contracts-paths",
        output_json=True,
        output_ndjson=False,
        tree=False,
    ),
    # ... more fixtures
]

@pytest.mark.parametrize(
    list(PathContractionFixture._fields),
    PATH_CONTRACTION_FIXTURES,
    ids=[fixture.test_id for fixture in PATH_CONTRACTION_FIXTURES],
)
def test_list_repos_path_contraction(...):
    # Test implementation

Documentation

Documentation already correct - examples in docs/cli/*.md were 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:

$ uv run vcspull list --json | jq '.[0].path'
"~/study/ai/tiktoken"

Commits

  1. 4de9970 - cli(feat[privacy]): Contract home paths in JSON/NDJSON output
  2. 2c4e749 - cli(test[privacy]): Add comprehensive tests for contracted JSON paths
  3. 52da2d7 - docs(CHANGES): Document path contraction as breaking change for v1.41.x

Checklist

@codecov
Copy link

codecov bot commented Oct 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.10%. Comparing base (639c049) to head (52da2d7).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #475   +/-   ##
=======================================
  Coverage   79.10%   79.10%           
=======================================
  Files          14       14           
  Lines        1527     1527           
  Branches      321      321           
=======================================
  Hits         1208     1208           
  Misses        201      201           
  Partials      118      118           

☔ 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.

tony added 3 commits October 25, 2025 05:15
why: Fix inconsistency where workspace_root used ~/ but path showed full
/home/username/ paths, exposing usernames and reducing portability
what:
- Apply contract_user_home() to path field in list.py (flat and tree views)
- Apply contract_user_home() to path field in status.py (status dict)
- Apply contract_user_home() to path field in sync.py (PlanEntry and events)
- All JSON/NDJSON output now consistently uses ~/... notation
- Human output already used tilde notation (unchanged)

Before:
  {"path": "/home/username/code/flask", "workspace_root": "~/code/"}

After:
  {"path": "~/code/flask", "workspace_root": "~/code/"}

Benefits:
- Consistency: Both path and workspace_root now use tilde
- Privacy: No username exposure in JSON dumps
- Portability: Configs/output work across different machines
- Matches shell conventions and user expectations

refs: Breaking change - automation may need to expand ~ to absolute paths
why: Ensure JSON/NDJSON output correctly contracts home directory paths
what:
- Add PathContractionFixture NamedTuple in test_list.py
- Add 3 parametrized test cases for list (JSON, NDJSON, JSON+tree)
- Add StatusPathContractionFixture NamedTuple in test_status.py
- Add 3 parametrized test cases for status (JSON, NDJSON, detailed)
- Assert paths start with ~/ and don't contain absolute home paths
- Follow project pattern: NamedTuple fixtures with test_id field

Coverage:
- test_list_repos_path_contraction: 3 scenarios
- test_status_repos_path_contraction: 3 scenarios
- Total: 6 new parametrized test cases

All 208 tests passing
why: Users consuming JSON/NDJSON output need to know about the change
what:
- Add Breaking Changes section to v1.41.x unreleased notes
- Document that all commands (list, status, sync) now use ~/
- Show before/after JSON examples
- Explain rationale: consistency, privacy, portability
- Note impact: automation may need to expand ~ if required

Breaking change: path field changed from /home/user/... to ~/...
@tony tony force-pushed the streamline-tildes-pt-2 branch from bc9e1e0 to 52da2d7 Compare October 25, 2025 10:15
@tony tony changed the title Streamline tildes pt 2 Contract home directory paths in JSON/NDJSON output Oct 25, 2025
@tony tony merged commit f807c5f into master Oct 25, 2025
10 checks passed
@tony tony deleted the streamline-tildes-pt-2 branch October 25, 2025 11:15
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.

1 participant