Skip to content

sync,status(feat): Apply target and dirty policy - #590

Merged
tony merged 6 commits into
masterfrom
feat/status-and-sync-policy
Nov 28, 2026
Merged

tony merged 6 commits into
masterfrom
feat/status-and-sync-policy

Conversation

@tony

@tony tony commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Forward configured target selectors, fetch remotes, and drift/dirty policy during sync.
  • Require explicit --yes confirmation before dirty: discard touches a repository.
  • Retain recovery tokens, conflicts, and outcomes across human, JSON, and NDJSON output, and return SyncExecution from vcspull.cli.sync.update_repo().
  • Report offline working-copy positions and resolved target drift in vcspull status.
  • Supervise per-repository sync workers in owned POSIX process groups on timeout or Ctrl-C without mutating PYTHONPATH.

Before / After

Python API (vcspull.cli.sync.update_repo) — Before:

project = update_repo(repo_dict)

Python API (vcspull.cli.sync.update_repo) — After:

execution = update_repo(repo_dict, yes=False)
project = execution.project
sync_result = execution.result

Dirty working tree with dirty: discard — without --yes vs with --yes:

$ vcspull sync project
✗ Failed syncing project: dirty: discard requires --yes before synchronization
$ vcspull sync project --yes
✓ Synced project → ~/code/project

Changes by area

Sync policy, recovery, and programmatic API

  • src/vcspull/_internal/sync.py: add SyncExecution, create_sync_project(), checkout_settings(), sync_result_data(), format_recovery_lines(), and require_discard_authorization(); convert GitRemote mappings for Mercurial without mutating push URLs.
  • src/vcspull/cli/sync.py and src/vcspull/cli/__init__.py: add --yes to vcspull sync; return SyncExecution from update_repo() (re-exported in vcspull.cli.sync) and attach SyncResult to SyncFailedError; emit update_state, preservation_state, recovery, conflicts, errors, and retained_recoveries in human, JSON, and NDJSON output; plan target drift and dirty policies in --dry-run.

Owned worker supervision

  • src/vcspull/_internal/sync_process.py: run each repository mutation in a start_new_session=True child process over a non-inheritable JSON control pipe with incremental UTF-8 stdout/stderr decoding and sys.argv package bootstrap (keeping child PYTHONPATH untouched); send SIGTERM then SIGKILL to the process group on timeout or SIGINT, then run a 1-second bounded inspect worker to report retained recovery tokens.

Offline status target resolution and documentation

  • src/vcspull/cli/status.py: inspect native position, target_position, policy, drifted, and errors across Git, Mercurial, and Subversion without fetching; pass protocol.allow=never and GIT_NO_LAZY_FETCH=1 on supplemental Git rev-list reads so partial clones never lazy-fetch objects during status.
  • docs/cli/status.md, docs/cli/sync.md, docs/internals/api/sync.md, docs/internals/api/sync_process.md, CHANGES, MIGRATION: document JSON schemas, SyncExecution, worker supervision, and breaking defaults.

Design decisions

  • Supervise each repository sync in an owned POSIX session (start_new_session=True + os.killpg) instead of a daemon thread so timeouts and SIGINT stop native VCS descendants before the next repository runs.
  • Bootstrap the worker's vcspull import root through sys.argv rather than os.environ["PYTHONPATH"] so native VCS binaries (such as Python-based /usr/bin/hg) and shell_command_after hooks never inherit vcspull's site-packages.
  • Run retained-recovery discovery (list_recoveries()) in a separate 1-second worker after timeout or SIGINT so an interrupted dirty: preserve run surfaces its recovery token without risking a second hang.
  • Require --yes on every vcspull sync invocation (and yes=True in update_repo()) even when dirty: discard is configured in YAML.

Companion PR

Stack

  1. ci,config(fix): Harden smoke test and VCS matrix #588 fix/ci-smoke-and-config-fixes
  2. config(feat): Add targets, VCS blocks, and schema #589 feat/config-v2-targets-and-git
  3. sync,status(feat): Apply target and dirty policy #590 feat/status-and-sync-policy (this PR)
  4. worktree(feat): Apply checkout policy under lock #578 options-streamline-and-git-filtering

Test plan

  • Verify target selectors, dirty: abort / preserve / discard (--yes guard), SyncExecution / SyncFailedError.result, and Mercurial separate fetch/push URLs:
$ uv run py.test tests/test_sync.py tests/test_cli.py tests/test_log.py
  • Verify offline vcspull status target drift across Git, Mercurial, and Subversion (mixed/switched working copies, VCS mismatch errors, and GIT_NO_LAZY_FETCH=1):
$ uv run py.test tests/cli/test_status.py
  • Verify SIGTERM-resistant descendant cleanup on timeout, clean child PYTHONPATH, split UTF-8 pipe framing, and post-timeout recovery inspection:
$ uv run py.test tests/cli/test_sync_watchdog.py
  • Verify real WIFSIGNALED(SIGINT) process-group termination and retained recovery reporting on Ctrl-C:
$ uv run py.test tests/cli/test_sync_sigint.py

Refs #123, #124, #393, #577, #587.

@tony
tony force-pushed the feat/config-v2-targets-and-git branch from b43cfbe to 66164c6 Compare November 28, 2026 17:46
@tony
tony force-pushed the feat/status-and-sync-policy branch from a282228 to 0e370bc Compare November 28, 2026 17:46
@tony
tony added this pull request to stack #591 November 28, 2026 17:46
@tony
tony force-pushed the feat/config-v2-targets-and-git branch from 66164c6 to dd39d38 Compare November 28, 2026 17:52
@tony
tony force-pushed the feat/status-and-sync-policy branch from 0e370bc to ad65bf4 Compare November 28, 2026 17:52
@tony
tony force-pushed the feat/config-v2-targets-and-git branch from dd39d38 to ec77c71 Compare November 28, 2026 20:54
@tony
tony force-pushed the feat/status-and-sync-policy branch from ad65bf4 to 9f6c18e Compare November 28, 2026 20:54
@tony
tony removed this pull request from stack #591 November 28, 2026 21:42
@tony
tony force-pushed the feat/status-and-sync-policy branch from 9f6c18e to 2da8586 Compare November 28, 2026 21:58
@tony
tony force-pushed the feat/config-v2-targets-and-git branch from ec77c71 to 224e504 Compare November 28, 2026 21:58
@tony
tony force-pushed the feat/status-and-sync-policy branch from 2da8586 to 16a4b94 Compare November 28, 2026 22:27
@tony
tony force-pushed the feat/config-v2-targets-and-git branch 2 times, most recently from 20cd43a to efbb876 Compare November 28, 2026 22:31
@tony
tony force-pushed the feat/status-and-sync-policy branch from 16a4b94 to 8661a7c Compare November 28, 2026 22:31
@tony
tony changed the base branch from feat/config-v2-targets-and-git to master November 28, 2026 22:32
tony added 6 commits November 28, 2026 16:32
why: Configured targets and dirty policies must reach the native backend,
and retained recovery details must survive CLI reporting.

what:
- Forward immutable target and policy values without changing input
- Require --yes before any configured discard accesses a repository
- Preserve recovery tokens, states, conflicts, and ordered failures
- Keep target-drift warnings visible in interactive output
- Verify native target selection, dirty policy, and machine output
why: Status and previews need the same target and policy contract as
sync, including unknown state when native metadata cannot resolve it.

what: Read Git, Hg, and SVN positions without fetching. Report resolved
drift and errors, preserve policy in previews, and distinguish Git
attachment work from revision drift. Share typed backend construction.
why: Timed-out threads keep mutating repositories and redirecting
parent output, while late recovery tokens can disappear.

what: Run sync in an owned process group with independent streamed
output and result channels. Stop native descendants before returning,
inspect retained recovery records after interruption, and preserve
complete results in human and machine output.

Verify native Git interruption, source-independent SVN discovery,
pipe-sized split UTF-8 frames, abnormal exits, and sequential timeout
cleanup. Full suite: 1671 passed, 1 skipped; 27 snapshots passed.
why: Loaded remotes use GitRemote objects that the Mercurial
backend cannot consume, and wire mappings must omit their key name.

what: Convert native path settings at the backend boundary and
serialize Git and Mercurial fetch/push URLs separately. Verify
selected-source updates through direct calls and owned workers.
@tony
tony force-pushed the feat/status-and-sync-policy branch from 8661a7c to 5b0b69b Compare November 28, 2026 22:32
@tony
tony merged commit 618cdd2 into master Nov 28, 2026
7 checks passed
@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.35983% with 113 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.76%. Comparing base (21c20f9) to head (5b0b69b).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
src/vcspull/_internal/sync_process.py 67.88% 74 Missing and 14 partials ⚠️
src/vcspull/cli/sync.py 73.25% 17 Missing and 6 partials ⚠️
src/vcspull/_internal/sync.py 98.07% 0 Missing and 1 partial ⚠️
src/vcspull/cli/status.py 98.48% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #590      +/-   ##
==========================================
- Coverage   84.40%   83.76%   -0.65%     
==========================================
  Files          33       35       +2     
  Lines        5221     5587     +366     
  Branches     1049     1117      +68     
==========================================
+ Hits         4407     4680     +273     
- Misses        539      615      +76     
- Partials      275      292      +17     

☔ View full report in Codecov by Harness.
📢 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
tony deleted the feat/status-and-sync-policy branch November 28, 2026 22:36
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