diff --git a/CHANGELOG.md b/CHANGELOG.md
index 82ab3f01..68ce4f32 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## 0.47.15 - 2026-11-16
+
+- Keep personal-manifest tracking updates within the selected manifest and its private ledger. Neither tracking value rewrites shared ignore files, changes hooks, stages files or removes the shared manifest README from the index. Preserve unrelated dirty primary files and report actions for the selected manifest.
+
## 0.47.14 - 2026-11-16
- Let lane and personal manifests without an authority declaration inherit the primary shared manifest's policy. Explicit declarations may restrict that policy but cannot grant additional capabilities. Report the effective policy and its source without copying inherited authority into the selected manifest.
diff --git a/README.md b/README.md
index 00123f0c..13218be8 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
Keep many long-lived pull requests clean, rebuildable, and publishable from one
manifest.
-Current version: `0.47.14`
+Current version: `0.47.15`
`syncwheel` is a small CLI and workflow model for maintainers who carry several
PR branches against an upstream repository and need those branches to stay
@@ -142,6 +142,11 @@ branch gets no control commit, and no Syncwheel push carries the manifest to a
stack, pull-request or delivery branch. New managed worktrees default to repo-relative
`.syncwheel/wt/`.
+With a personal manifest selected, `repo tracking set` changes only that manifest's
+policy and private ledger. Both tracking values leave shared ignore files, hooks,
+the manifest README and Git indexes unchanged. Personal metadata must already be
+ignored and untracked; changing its policy does not migrate the shared repository.
+
`authority` declares how far agents may take a change on their own. A repo
with `mode=ai-managed` and `source_change` allowed lets an agent edit, test,
commit, push, open and merge the PR without asking at each step; `runtime_change`
diff --git a/VERSION b/VERSION
index 6ae95b5c..676ecf5e 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.47.14
+0.47.15
diff --git a/docs/ai-agents.md b/docs/ai-agents.md
index 72159812..e18ff98e 100644
--- a/docs/ai-agents.md
+++ b/docs/ai-agents.md
@@ -291,6 +291,10 @@ ask for the intended mode and persist it with
full policy and migration behavior. An installable agent skill that encodes this
lives in [`skills/syncwheel/SKILL.md`](../skills/syncwheel/SKILL.md).
+Selecting a personal manifest limits `repo tracking set` to that manifest and its
+private ledger. It does not migrate shared ignore files, hooks or the Git index.
+The selected private metadata must already be ignored and untracked.
+
## Repository authority
The manifest can also say how much of the delivery pipeline you may run without
diff --git a/docs/index.html b/docs/index.html
index fddc1aca..0ff44a2e 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -1826,7 +1826,7 @@
-
AI-ready Git coordination v0.47.14
+
AI-ready Git coordination v0.47.15
Move at machine speed. Stay in control.
Syncwheel coordinates every Git lane used by humans, AI agents, CI and delivery systems—without sacrificing review, safety or recovery.
@@ -2602,7 +2602,7 @@
Your first verified plan in minutes.
- syncwheel v0.47.14 · MIT · a NestDevLab project
+ syncwheel v0.47.15 · MIT · a NestDevLab project
diff --git a/docs/manifest-tracking.md b/docs/manifest-tracking.md
index 12ff6cb5..dc4ac4af 100644
--- a/docs/manifest-tracking.md
+++ b/docs/manifest-tracking.md
@@ -130,7 +130,7 @@ the repository does not own.
## Migration
-Use `repo tracking set` to migrate between modes:
+With the shared manifest selected, use `repo tracking set` to migrate between modes:
- `local-only -> git-tracked`: writes the manifest policy, adds the managed
`.gitignore` block, removes the managed `.git/info/exclude` block, and stages
@@ -143,6 +143,14 @@ The CLI only edits Syncwheel-managed blocks. If `.gitignore` contains manual
`.syncwheel/` ignore entries outside the managed block, `repo tracking set
git-tracked --apply` stops and asks for manual audit.
+With a personal manifest selected, the command updates only its policy and private
+ledger. This applies to both `git-tracked` and `local-only`, including a personal
+manifest selected through `--manifest`, a profile or an alias. The personal
+manifest and ledger must already be ignored and untracked. The command leaves
+shared `.gitignore`, `info/exclude`, hooks, the manifest README and Git indexes
+unchanged, including when the primary has unrelated unstaged product changes.
+A personal policy change does not authorize migration of shared repository files.
+
Tracking-policy migration does not silently upgrade a legacy manifest to
active-active coordination. After confirming the publication remote and shared
ownership boundary, opt in separately:
diff --git a/openpack.json b/openpack.json
index 97279e48..b44837c1 100644
--- a/openpack.json
+++ b/openpack.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 2,
"name": "NestDevLab/syncwheel",
- "version": "0.47.14",
+ "version": "0.47.15",
"provides": [
{
"type": "skills",
diff --git a/scripts/syncwheel.py b/scripts/syncwheel.py
index 02d42029..f2d3922b 100755
--- a/scripts/syncwheel.py
+++ b/scripts/syncwheel.py
@@ -2959,6 +2959,17 @@ def resolve_manifest_path(repo_root, repo_value=None, manifest_override=None, pe
return repo_root / '.syncwheel' / 'manifest.json'
+def resolve_command_manifest_selection(args):
+ tracking_selection = getattr(args, '_tracking_selection', None)
+ if tracking_selection is not None:
+ _, repo_root, manifest_path, _ = tracking_selection
+ return repo_root, manifest_path
+ repo_root = resolve_repo_root(args.repo)
+ return repo_root, resolve_manifest_path(
+ repo_root, args.repo, getattr(args, 'manifest', None), getattr(args, 'personal', None)
+ )
+
+
def branch_exists(repo_root, branch):
return git(repo_root, 'show-ref', '--verify', '--quiet', f'refs/heads/{branch}', check=False).returncode == 0
@@ -18094,7 +18105,67 @@ def managed_block_exists(path, marker):
return any(line.strip() == marker for line in read_text_if_exists(path).splitlines())
+def tracking_manifest_scope(repo_root, manifest_path):
+ """Classify the selected path before following any metadata symlinks."""
+ checkout = Path(repo_root).resolve()
+ shared_path = primary_authority_manifest_path(checkout)
+ primary = shared_path.parent.parent
+ selected = Path(os.path.abspath(manifest_path))
+ if selected == shared_path:
+ return 'shared', primary, primary
+ for owner in dict.fromkeys((checkout, primary)):
+ if (
+ selected.parent == owner / '.syncwheel' / 'manifests'
+ and selected.name.endswith('.local.json')
+ ):
+ return 'personal', owner, primary
+ return 'alternate', checkout, primary
+
+
+def require_private_tracking_path(owner, path, *, directory=False):
+ """Refuse redirects or special files anywhere in a private metadata path."""
+ relative = path.relative_to(owner)
+ candidate = owner
+ for part in relative.parts:
+ candidate /= part
+ try:
+ observed = candidate.lstat()
+ except FileNotFoundError:
+ return
+ mode = observed.st_mode
+ if stat.S_ISLNK(mode):
+ raise SyncwheelError(f'private tracking metadata cannot be a symbolic link: {candidate}')
+ if directory or candidate != path:
+ if not stat.S_ISDIR(mode):
+ raise SyncwheelError(f'private tracking metadata directory is not a directory: {candidate}')
+ elif not stat.S_ISREG(mode) or observed.st_nlink > 1:
+ raise SyncwheelError(f'private tracking metadata must be a regular, unlinked file: {candidate}')
+
+
+def tracking_set_selection(args):
+ repo_value = args.repo or os.environ.get(ENV_REPO)
+ repo_root = resolve_repo_root(repo_value)
+ manifest_path = resolve_manifest_path(repo_root, repo_value, args.manifest, args.personal)
+ scope, owner, primary = tracking_manifest_scope(repo_root, manifest_path)
+ if scope == 'personal':
+ manifest_path = Path(os.path.abspath(manifest_path))
+ require_private_tracking_path(owner, manifest_path)
+ elif scope != 'shared' or repo_root.resolve() != primary:
+ raise SyncwheelError(
+ 'tracking migration requires the canonical manifest in the primary checkout; '
+ 'select a personal manifest to change private tracking'
+ )
+ else:
+ validate_selected_primary_authority_path(repo_root, manifest_path)
+ return scope, owner, Path(os.path.abspath(manifest_path)), primary
+
+
def syncwheel_tracking_report(repo_root, manifest_path):
+ scope, owner, _ = tracking_manifest_scope(repo_root, manifest_path)
+ if scope == 'personal':
+ manifest_path = Path(os.path.abspath(manifest_path))
+ require_private_tracking_path(owner, manifest_path)
+ repo_root = owner
validate_selected_primary_authority_path(repo_root, manifest_path)
manifest, manifest_path = _manifest_storage.load_manifest(repo_root, manifest_path)
manifest_present = manifest is not None
@@ -18108,7 +18179,19 @@ def syncwheel_tracking_report(repo_root, manifest_path):
warnings = []
actions = []
- if not manifest_present:
+ if scope != 'shared':
+ if scope == 'personal':
+ if not manifest_present:
+ actions.append('select an existing personal manifest')
+ elif manifest_tracked or git(
+ repo_root, 'check-ignore', '--quiet', '--no-index', '--', manifest_relative, check=False,
+ ).returncode != 0:
+ warnings.append('personal tracking requires an untracked, already ignored manifest')
+ elif tracking is None:
+ actions.append('set tracking on the selected personal manifest with --apply')
+ else:
+ actions.append('select the canonical or a personal manifest to change tracking')
+ elif not manifest_present:
actions.append('create a manifest with syncwheel init, then set syncwheel_tracking')
elif tracking is None:
warnings.append('syncwheel_tracking is not set; choose git-tracked or local-only before branch/push/PR work')
@@ -18135,6 +18218,7 @@ def syncwheel_tracking_report(repo_root, manifest_path):
resolve_repository_authority(repo_root, manifest, manifest_path) if manifest_present else (None, None)
)
return {
+ 'tracking_scope': scope,
'repo_root': str(repo_root),
'manifest_path': str(manifest_path),
'manifest_present': manifest_present,
@@ -18157,6 +18241,7 @@ def syncwheel_tracking_report(repo_root, manifest_path):
def print_syncwheel_tracking_report(report):
+ print(f"tracking_scope: {report['tracking_scope']}")
print(f"repo: {report['repo_root']}")
print(f"manifest: {report['manifest_path'] if report['manifest_present'] else 'missing'}")
print(f"syncwheel_tracking: {report['syncwheel_tracking'] or 'missing'}")
@@ -18586,9 +18671,50 @@ def git_rm_cached_paths(repo_root, paths):
git(repo_root, 'rm', '--cached', '--ignore-unmatch', '--', *relatives)
+def require_private_tracking_update(args, owner, manifest_path, primary):
+ from syncwheel_stack_adoption import pending_adoptions
+
+ require_private_tracking_path(owner, manifest_path)
+ require_metadata_primary_index(primary)
+ if owner != primary:
+ require_metadata_primary_index(owner)
+ for root, path in dict.fromkeys(((owner, manifest_path), (primary, primary / '.syncwheel' / 'manifest.json'))):
+ events_dir = _manifest_storage.ledger_events_dir(root, path)
+ require_private_tracking_path(root, events_dir, directory=True)
+ for segment in events_dir.glob('*.jsonl'):
+ require_private_tracking_path(root, segment)
+ events = load_ledger_events(root, path)
+ if pending_control_manifest_intents(events):
+ raise SyncwheelError('control manifest recovery is pending; complete the interrupted operation first')
+ if path == manifest_path and pending_adoptions(events):
+ raise SyncwheelError('interrupted stack adoption; complete the pending adoption first')
+ private_paths = (
+ _manifest_storage.ledger_root(owner, manifest_path) / 'ledger.lock',
+ _manifest_storage.ledger_checkpoint_path(owner, manifest_path),
+ )
+ for path in private_paths:
+ require_private_tracking_path(owner, path)
+ require_private_metadata_paths(args, owner, manifest_path)
+
+
def command_repo_tracking_set(args):
- repo_root = resolve_repo_root(args.repo)
- manifest_path = resolve_manifest_path(repo_root, args.repo, args.manifest, args.personal)
+ selection = getattr(args, '_tracking_selection', None) or tracking_set_selection(args)
+ scope, repo_root, manifest_path, primary = selection
+ if scope == 'personal' and args.apply:
+ require_private_tracking_update(args, repo_root, manifest_path, primary)
+ with manifest_write_transaction(
+ repo_root, manifest_path, 'personal-tracking', commit_tracked_changes=False,
+ ):
+ require_private_tracking_update(args, repo_root, manifest_path, primary)
+ transaction = _manifest_storage.active_manifest_write_transaction(manifest_path)
+ transaction['preserveGitignore'] = True
+ return update_repo_tracking(args, repo_root, manifest_path, personal=True)
+ return update_repo_tracking(args, repo_root, manifest_path, personal=scope == 'personal')
+
+
+def update_repo_tracking(args, repo_root, manifest_path, *, personal):
+ if not personal:
+ validate_selected_primary_authority_path(repo_root, manifest_path)
manifest, manifest_path = _manifest_storage.load_manifest(repo_root, manifest_path)
if not manifest:
raise SyncwheelError(f'manifest not found: {manifest_path}')
@@ -18599,7 +18725,7 @@ def command_repo_tracking_set(args):
manifest['syncwheel_worktree_root'] = worktree_root
warnings = []
- if tracking == SYNCWHEEL_TRACKING_GIT_TRACKED:
+ if not personal and tracking == SYNCWHEEL_TRACKING_GIT_TRACKED:
conflicts = gitignore_manual_syncwheel_conflicts(repo_root)
if conflicts:
warnings.append(
@@ -18609,16 +18735,26 @@ def command_repo_tracking_set(args):
if warnings and args.apply:
raise SyncwheelError('; '.join(warnings))
- if not args.apply:
+ if personal or not args.apply:
report = syncwheel_tracking_report(repo_root, manifest_path)
report['syncwheel_tracking'] = tracking
report['syncwheel_tracking_present'] = True
report['syncwheel_worktree_root'] = worktree_root
report['effective_worktree_root'] = str(resolve_worktree_root_path(repo_root, worktree_root))
report['warnings'].extend(warnings)
- report['actions'].append(f'apply syncwheel_tracking={tracking}')
- print_syncwheel_tracking_report(report)
- print('dry_run: pass --apply to write this setup')
+ if args.apply:
+ save_manifest_with_ledger(
+ repo_root, manifest_path, manifest, 'repo_tracking_set',
+ {'syncwheel_tracking': tracking, 'syncwheel_worktree_root': worktree_root},
+ )
+ else:
+ report['actions'].append(f'apply syncwheel_tracking={tracking}')
+ if personal and args.json:
+ print(json.dumps({**report, 'apply': args.apply}, indent=2))
+ else:
+ print_syncwheel_tracking_report(report)
+ if not args.apply:
+ print('dry_run: pass --apply to write this setup')
return 0
readme_path = repo_root / '.syncwheel' / 'manifests' / 'README.md'
@@ -19430,7 +19566,7 @@ def require_private_metadata_paths(args, repo_root, manifest_path):
_manifest_storage.ledger_events_dir(repo_root, manifest_path) / '000001.jsonl',
_manifest_storage.next_ledger_segment_path(repo_root, manifest_path, create_directory=False),
]
- if args.func == command_repo_authority_set:
+ if args.func in {command_repo_authority_set, command_repo_tracking_set}:
paths.append(manifest_path)
elif args.func in {command_repo_pr_merge_policy_set, command_repo_pr_merge_policy_clear}:
paths.append(checked_repo_profile_path(repo_root))
@@ -19450,15 +19586,17 @@ def primary_checkout_preflight(args):
command_hooks_ref_guard,
}:
return
- repo_root = resolve_repo_root(args.repo)
- worktrees = get_worktrees(repo_root)
- primary_root = Path(worktrees[0]['path']).resolve() if worktrees else repo_root
- selected_path = resolve_manifest_path(
- repo_root, args.repo, getattr(args, 'manifest', None), getattr(args, 'personal', None)
- )
- manifest_path = resolve_manifest_path(
- primary_root, str(primary_root), getattr(args, 'manifest', None), getattr(args, 'personal', None)
- )
+ repo_root, selected_path = resolve_command_manifest_selection(args)
+ tracking_selection = getattr(args, '_tracking_selection', None)
+ if tracking_selection is not None:
+ primary_root = tracking_selection[3]
+ manifest_path = selected_path
+ else:
+ worktrees = get_worktrees(repo_root)
+ primary_root = Path(worktrees[0]['path']).resolve() if worktrees else repo_root
+ manifest_path = resolve_manifest_path(
+ primary_root, str(primary_root), getattr(args, 'manifest', None), getattr(args, 'personal', None)
+ )
manifest, _ = _manifest_storage.load_manifest(primary_root, manifest_path)
metadata_scope = False
if command_behavior(args)['primaryScope'] == 'metadata' and syncwheel_mutation_requested(args):
@@ -19559,10 +19697,7 @@ def default_hook_convergence_requested(args):
def converge_default_repository_hooks(args):
if not default_hook_convergence_requested(args):
return None
- repo_root = resolve_repo_root(args.repo)
- manifest_path = resolve_manifest_path(
- repo_root, args.repo, getattr(args, 'manifest', None), getattr(args, 'personal', None)
- )
+ repo_root, manifest_path = resolve_command_manifest_selection(args)
if not manifest_path.exists():
return None
manifest, _ = _manifest_storage.load_manifest(repo_root, manifest_path)
@@ -19621,10 +19756,7 @@ def governed_worktree_mutation_requested(args):
def governed_worktree_preflight(args):
if not hasattr(args, 'repo'):
return
- repo_root = resolve_repo_root(args.repo)
- manifest_path = resolve_manifest_path(
- repo_root, args.repo, getattr(args, 'manifest', None), getattr(args, 'personal', None)
- )
+ repo_root, manifest_path = resolve_command_manifest_selection(args)
manifest, _ = _manifest_storage.load_manifest(repo_root, manifest_path)
if manifest is None:
return
@@ -19916,13 +20048,9 @@ def recover_control_manifest_before_command(args):
# Every other manifest writer must still settle a pending intent before
# it replaces the source the interrupted operation was persisting.
return None
- repo_root = resolve_repo_root(args.repo)
- manifest_path = resolve_manifest_path(
- repo_root,
- args.repo,
- getattr(args, 'manifest', None),
- getattr(args, 'personal', None),
- )
+ repo_root, manifest_path = resolve_command_manifest_selection(args)
+ if getattr(args, '_tracking_selection', None) is not None:
+ validate_selected_primary_authority_path(repo_root, manifest_path)
manifest, _ = _manifest_storage.load_manifest(repo_root, manifest_path)
if args.func == command_int_rebuild:
require_int_rebuild_reason(args, repo_root, manifest, manifest_path)
@@ -19950,9 +20078,7 @@ def stack_adoption_preflight(args):
if not hasattr(args, 'repo') or not syncwheel_mutation_requested(args):
return
from syncwheel_stack_adoption import pending_adoptions
- root = resolve_repo_root(args.repo)
- path = resolve_manifest_path(root, args.repo, getattr(args, 'manifest', None),
- getattr(args, 'personal', None))
+ root, path = resolve_command_manifest_selection(args)
pending = pending_adoptions(load_ledger_events(root, path))
if not pending:
return
@@ -20079,12 +20205,19 @@ def main():
command_hooks_worktree_guard,
command_hooks_ref_guard,
}
- if not guard_callback:
- global SYNCWHEEL_OWNS_REF_MOVES, SYNCWHEEL_REF_AUTH_REPO
- SYNCWHEEL_OWNS_REF_MOVES = True
- if hasattr(args, 'repo'):
- SYNCWHEEL_REF_AUTH_REPO = resolve_repo_root(args.repo)
+ global SYNCWHEEL_OWNS_REF_MOVES, SYNCWHEEL_REF_AUTH_REPO
try:
+ if args.func in {command_repo_tracking_set, command_repo_tracking_status}:
+ args.repo = args.repo or os.environ.get(ENV_REPO)
+ if args.func == command_repo_tracking_set:
+ args._tracking_selection = tracking_set_selection(args)
+ if args._tracking_selection[0] == 'personal':
+ return command_repo_tracking_set(args)
+ args.repo = str(args._tracking_selection[1])
+ if not guard_callback:
+ SYNCWHEEL_OWNS_REF_MOVES = True
+ if hasattr(args, 'repo'):
+ SYNCWHEEL_REF_AUTH_REPO = resolve_repo_root(args.repo)
if args.func in {
command_status, command_repo_tracking_status,
command_repo_authority_status, command_repo_authority_set,
@@ -20108,10 +20241,7 @@ def main():
converge_default_repository_hooks(args)
with coordination_publication_lock_for_command(args):
if manifest_mutation_requested(args) and hasattr(args, 'repo'):
- repo_root = resolve_repo_root(args.repo)
- manifest_path = resolve_manifest_path(
- repo_root, args.repo, getattr(args, 'manifest', None), getattr(args, 'personal', None)
- )
+ repo_root, manifest_path = resolve_command_manifest_selection(args)
if args.func != command_init and manifest_path.exists():
existing_manifest, _ = _manifest_storage.load_manifest(repo_root, manifest_path)
if existing_manifest:
diff --git a/skills/syncwheel/SKILL.md b/skills/syncwheel/SKILL.md
index 563cc7bf..cb7d4101 100644
--- a/skills/syncwheel/SKILL.md
+++ b/skills/syncwheel/SKILL.md
@@ -694,10 +694,16 @@ Benefits:
integration tree. Either way, no Syncwheel push carries the manifest to a stack,
pull-request or delivery branch.
-Use `syncwheel repo tracking set ... --apply` to migrate between modes. The CLI
+With the shared manifest selected, use `syncwheel repo tracking set ... --apply`
+to migrate between modes. The CLI
edits only Syncwheel-managed ignore blocks; if manual `.gitignore` entries would
hide `.syncwheel/manifest.json`, stop and ask for a repository decision.
+With a personal manifest selected, either tracking value changes only that
+manifest and its private ledger. The command requires already ignored, untracked
+private metadata and preserves shared ignore files, hooks, the manifest README
+and Git indexes. Do not treat a personal policy change as shared migration approval.
+
## Handoff checklist
Before final response after touching a Git repo:
diff --git a/tests/test_personal_tracking.py b/tests/test_personal_tracking.py
new file mode 100644
index 00000000..383a0457
--- /dev/null
+++ b/tests/test_personal_tracking.py
@@ -0,0 +1,353 @@
+import contextlib
+import importlib
+import io
+import json
+import subprocess
+import sys
+import unittest
+from pathlib import Path
+from unittest import mock
+
+import test_metadata_preflight as fixtures
+
+
+class PersonalTrackingTest(unittest.TestCase):
+ def setUp(self):
+ self.case = fixtures.MetadataPreflightTest()
+ self.addCleanup(self.case.doCleanups)
+ self.case.setUp()
+ self.repo = self.case.repo
+ self.module = self.case.module
+ self.readme = self.repo / '.syncwheel' / 'manifests' / 'README.md'
+ self.readme.parent.mkdir(exist_ok=True)
+ self.readme.write_text('# Shared manifest documentation\n')
+ self.case.ignore.write_text('*.cache\n')
+ self.module.ensure_syncwheel_metadata_excluded(self.repo, 'git-tracked')
+ self.case.git('add', '.gitignore', str(self.readme))
+ self.case.git('commit', '-qm', 'Track shared ignore and manifest documentation')
+ self.personal = self.case.create_personal_manifest('review', 'git-tracked')
+ self.profile = self.repo / '.syncwheel' / 'profile.local.json'
+ self.profile.write_text('{}\n')
+ self.assertEqual(self.case.git('ls-files', '--', '.gitignore', str(self.readme)), (
+ b'.gitignore\n.syncwheel/manifests/README.md\n'
+ ))
+ self.assertEqual(self.case.git('ls-files', '--', str(self.personal)), b'')
+ self.case.git('check-ignore', '--quiet', str(self.personal))
+ ledger = self.module.ledger_root(self.repo, self.personal)
+ self.case.git('check-ignore', '--quiet', str(ledger / 'events' / '000001.jsonl'))
+ self.assertEqual(self.case.git('status', '--porcelain'), b'')
+
+ def cli(self, *args, cwd=None, extra_env=None):
+ env = self.case.fixture._clean_env()
+ env.pop('SYNCWHEEL_PERSONAL', None)
+ env.pop('SYNCWHEEL_REPO', None)
+ env.update(
+ GIT_OPTIONAL_LOCKS='0',
+ SYNCWHEEL_UPDATE_MODE='off',
+ SYNCWHEEL_REPO_REGISTRY=str(self.case.fixture.temp_root / 'isolated-registry.json'),
+ )
+ env.update(extra_env or {})
+ return subprocess.run(
+ [sys.executable, str(fixtures.guard_fixtures.MODULE_PATH), *args],
+ cwd=cwd or self.repo, env=env, text=True, capture_output=True,
+ )
+
+ def snapshot(self):
+ return {
+ 'ignore': self.case.ignore.read_bytes(),
+ 'readme': self.readme.read_bytes(),
+ 'shared': self.case.manifest_path.read_bytes(),
+ 'index': (self.repo / '.git' / 'index').read_bytes(),
+ 'staging': self.case.git('ls-files', '--stage'),
+ 'exclude': (self.repo / '.git' / 'info' / 'exclude').read_bytes(),
+ 'refs': self.case.git('for-each-ref'),
+ 'worktrees': self.case.git('worktree', 'list', '--porcelain'),
+ 'product': self.case.product.read_bytes(),
+ 'untracked': self.case.read_if_present(self.repo / 'untracked-product'),
+ 'hooks': self.case.fixture.hook_bundle_bytes(),
+ 'shared_ledger': self.module.load_ledger_events(self.repo, self.case.manifest_path),
+ }
+
+ def test_personal_local_only_does_not_modify_shared_tracking(self):
+ before = self.snapshot()
+
+ result = self.cli('repo', 'tracking', 'set', 'local-only', '--apply', '-p', 'review')
+
+ self.assertEqual(result.returncode, 0, result.stderr)
+ after = self.snapshot()
+ self.assertEqual([key for key in before if before[key] != after[key]], [])
+ self.assertEqual(json.loads(self.personal.read_text())['syncwheel_tracking'], 'local-only')
+ self.assertEqual(self.module.load_ledger_events(self.repo, self.personal)[-1]['payload']['reason'],
+ 'repo_tracking_set')
+
+ def assert_private_update(self, requested, *selection, cwd=None, extra_env=None, path=None):
+ path = path or self.personal
+ before = self.snapshot()
+ original = json.loads(path.read_text())
+ result = self.cli('repo', 'tracking', 'set', requested, '--apply', '--json',
+ *selection, cwd=cwd, extra_env=extra_env)
+
+ self.assertEqual(result.returncode, 0, result.stderr)
+ report = json.loads(result.stdout)
+ self.assertEqual(report['tracking_scope'], 'personal')
+ self.assertEqual(report['syncwheel_tracking'], requested)
+ self.assertFalse(report['manifest_tracked'])
+ self.assertEqual(Path(report['manifest_path']).resolve(), path)
+ shared_actions = ('git add', 'git rm', 'managed .gitignore', 'info/exclude')
+ for action in report['actions']:
+ self.assertFalse(any(item in action for item in shared_actions), action)
+ current = json.loads(path.read_text())
+ self.assertEqual(current['syncwheel_tracking'], requested)
+ self.assertEqual(current['stacks'], original['stacks'])
+ self.assertEqual(current['integration'], original['integration'])
+ events = self.module.load_ledger_events(cwd or self.repo, path)
+ self.assertEqual(events[-1]['payload']['reason'], 'repo_tracking_set')
+ self.assertEqual(self.snapshot(), before)
+
+ def assert_refusal_preserves_state(self, detail, *selection):
+ before = self.snapshot()
+ personal = self.personal.read_bytes()
+ ledger = self.module.load_ledger_events(self.repo, self.personal)
+ result = self.cli('repo', 'tracking', 'set', 'local-only', '--apply', *selection)
+
+ self.assertEqual(result.returncode, 2, result.stderr)
+ self.assertRegex(result.stderr, detail)
+ self.assertEqual(self.personal.read_bytes(), personal)
+ self.assertEqual(self.module.load_ledger_events(self.repo, self.personal), ledger)
+ self.assertEqual(self.snapshot(), before)
+
+ def test_both_directions_with_explicit_manifest_and_dirty_primary(self):
+ self.case.dirty_product()
+ self.assert_private_update('local-only', '-M', str(self.personal))
+ self.assert_private_update(
+ 'git-tracked', '-M', str(self.personal), extra_env={'GIT_OPTIONAL_LOCKS': '1'},
+ )
+
+ def test_personal_selection_via_profile_environment_and_alias(self):
+ registry = self.case.fixture.temp_root / 'repo-registry.json'
+ registry.write_text(json.dumps({
+ 'review-alias': {'path': str(self.repo), 'manifest': str(self.personal)},
+ }))
+ profile = json.loads(self.profile.read_text())
+
+ self.assert_private_update('local-only', extra_env={'SYNCWHEEL_PERSONAL': 'review'})
+ self.profile.write_text(json.dumps({**profile, 'personal': 'review'}))
+ self.assert_private_update('git-tracked')
+ self.profile.write_text(json.dumps(profile))
+ self.assert_private_update('local-only', '--repo', 'review-alias',
+ extra_env={'SYNCWHEEL_REPO_REGISTRY': str(registry)})
+
+ def test_linked_worktree_keeps_both_indexes_and_checked_out_metadata(self):
+ lane = self.case.fixture.temp_root / 'linked-review'
+ self.case.git('worktree', 'add', '--detach', '-q', str(lane))
+ lane_path = self.module.personal_manifest_path(lane, 'review')
+ lane_path.write_bytes(self.personal.read_bytes())
+ lane_index = Path(self.case.git(
+ '-C', str(lane), 'rev-parse', '--path-format=absolute', '--git-path', 'index',
+ ).decode().strip())
+ files = (lane_index, lane / '.gitignore', lane / self.readme.relative_to(self.repo),
+ lane / '.syncwheel' / 'manifest.json', self.personal)
+ before = [path.read_bytes() for path in files]
+ self.case.dirty_product()
+
+ self.assert_private_update('local-only', '-p', 'review', cwd=lane, path=lane_path)
+
+ self.assertEqual([path.read_bytes() for path in files], before)
+ self.assert_private_update('local-only', '-M', str(self.personal), cwd=lane)
+ self.assertEqual([path.read_bytes() for path in files[:-1]], before[:-1])
+
+ def test_personal_tracking_preview_has_no_shared_git_actions(self):
+ before = self.snapshot()
+ personal = self.personal.read_bytes()
+
+ result = self.cli('repo', 'tracking', 'set', 'local-only', '-p', 'review')
+
+ self.assertEqual(result.returncode, 0, result.stderr)
+ for action in ('git add', 'git rm', 'managed .gitignore', 'info/exclude'):
+ self.assertNotIn(action, result.stdout)
+ status = self.cli('repo', 'tracking', 'status', '--json', '-p', 'review')
+ self.assertEqual(status.returncode, 0, status.stderr)
+ report = json.loads(status.stdout)
+ self.assertEqual(report['tracking_scope'], 'personal')
+ self.assertEqual(report['actions'], [])
+ self.assertEqual(self.personal.read_bytes(), personal)
+ self.assertEqual(self.module.load_ledger_events(self.repo, self.personal), [])
+ self.assertEqual(self.snapshot(), before)
+
+ def test_tracked_personal_manifest_is_refused_on_clean_primary(self):
+ self.case.git('add', '-f', str(self.personal))
+ self.case.git('commit', '-qm', 'Track a personal manifest for the refusal fixture')
+
+ self.assert_refusal_preserves_state('untracked', '-p', 'review')
+
+ def test_unignored_personal_ledger_is_refused_before_write(self):
+ self.case.ignore.write_text(self.case.ignore.read_text().replace(
+ '.syncwheel/manifests/*.local-ledger/\n', '',
+ ))
+ self.case.git('add', '.gitignore')
+ self.case.git('commit', '-qm', 'Remove personal ledger exclusion')
+
+ self.assert_refusal_preserves_state('ignored', '-p', 'review')
+
+ def test_unignored_personal_manifest_is_refused_before_write(self):
+ self.case.ignore.write_text(self.case.ignore.read_text().replace(
+ '.syncwheel/manifests/*.local.json\n', '',
+ ))
+ self.case.git('add', '.gitignore')
+ self.case.git('commit', '-qm', 'Remove personal manifest exclusion')
+
+ self.assert_refusal_preserves_state('ignored', '-p', 'review')
+
+ def test_personal_symlink_to_shared_manifest_is_refused_on_clean_primary(self):
+ self.personal.unlink()
+ self.personal.symlink_to(self.case.manifest_path)
+ self.assertEqual(self.case.git('status', '--porcelain'), b'')
+
+ for selection in (('-p', 'review'), ('-M', str(self.personal))):
+ with self.subTest(selection=selection):
+ self.assert_refusal_preserves_state('symbolic link|symlink', *selection)
+
+ self.assertTrue(self.personal.is_symlink())
+ self.assertEqual(self.personal.resolve(), self.case.manifest_path)
+
+ def test_personal_tracking_refuses_staged_product_and_conflicts(self):
+ self.case.dirty_product()
+ self.case.git('add', 'seed')
+ self.assert_refusal_preserves_state('unrelated staged paths', '-p', 'review')
+
+ oid = self.case.git('rev-parse', 'HEAD:seed').decode().strip()
+ self.case.git('update-index', '--force-remove', 'seed')
+ subprocess.run(
+ ['git', 'update-index', '--index-info'], cwd=self.repo, check=True,
+ input=f'100644 {oid} 1\tseed\n100644 {oid} 2\tseed\n100644 {oid} 3\tseed\n'.encode(),
+ )
+ self.assert_refusal_preserves_state('index conflicts', '-p', 'review')
+
+ def test_pending_shared_recovery_is_not_run_on_clean_or_dirty_primary(self):
+ shared_path = self.case.manifest_path
+ manifest, _ = self.module.load_manifest(self.repo, shared_path)
+ branch = manifest['integration']['branch']
+ tip = self.case.git('rev-parse', branch).decode().strip()
+ manifest['defaults']['replay_mode'] = 'auto'
+ store = importlib.import_module('syncwheel_manifest_store')
+
+ def interrupt(stage):
+ if stage == 'intent_saved':
+ raise RuntimeError('simulated process interruption after native intent')
+
+ with (
+ self.module.manifest_write_transaction(self.repo, shared_path),
+ mock.patch.object(store, 'control_manifest_io_checkpoint', side_effect=interrupt),
+ self.assertRaisesRegex(RuntimeError, 'simulated process interruption'),
+ ):
+ self.module.restore_control_manifest_after_integration_rebuild(
+ self.repo, shared_path, manifest, tip, 'control',
+ reason='Exercise native interrupted control persistence',
+ command='syncwheel int rebuild',
+ )
+
+ events = self.module.load_ledger_events(self.repo, shared_path)
+ self.assertEqual(len(self.module.pending_control_manifest_intents(events)), 1)
+ self.assertEqual(self.case.git('status', '--porcelain'), b'')
+ for dirty in (False, True):
+ with self.subTest(dirty_primary=dirty):
+ if dirty:
+ self.case.dirty_product()
+ self.assert_refusal_preserves_state('control manifest recovery is pending',
+ '-p', 'review')
+
+ def test_profile_selection_race_cannot_update_shared_tracking(self):
+ original_profile = self.profile.read_bytes()
+ self.profile.write_text(json.dumps({**json.loads(original_profile), 'personal': 'review'}))
+ selected = self.module.tracking_set_selection
+ original_personal = self.personal.read_bytes()
+ expected_snapshots = []
+
+ def change_profile_after_first_selection(args):
+ selection = selected(args)
+ if not expected_snapshots:
+ self.assertEqual(selection[0], 'personal')
+ self.profile.write_bytes(original_profile)
+ expected_snapshots.append(self.snapshot())
+ return selection
+
+ argv = [
+ 'syncwheel', 'repo', 'tracking', 'set', 'local-only', '--apply',
+ '--repo', str(self.repo),
+ ]
+ with (
+ mock.patch.object(sys, 'argv', argv),
+ mock.patch.object(self.module, 'tracking_set_selection',
+ side_effect=change_profile_after_first_selection),
+ contextlib.redirect_stdout(io.StringIO()),
+ contextlib.redirect_stderr(io.StringIO()),
+ ):
+ result = self.module.main()
+
+ self.assertEqual(len(expected_snapshots), 1)
+ self.assertIn(result, (0, 2))
+ self.assertEqual(self.snapshot(), expected_snapshots[0])
+ if result:
+ self.assertEqual(self.personal.read_bytes(), original_personal)
+ else:
+ self.assertEqual(json.loads(self.personal.read_text())['syncwheel_tracking'], 'local-only')
+
+ def test_shared_tracking_race_cannot_bypass_pending_adoption(self):
+ adopt = ('stack', 'set', 'feature', '--base', 'HEAD', '--adopt-tip', 'HEAD')
+ preview = self.cli(*adopt)
+ self.assertEqual(preview.returncode, 0, preview.stderr)
+ plan = json.loads(preview.stdout)
+ args = self.module.build_parser().parse_args([
+ *adopt, '--plan-digest', plan['planDigest'], '--apply', '--repo', str(self.repo),
+ ])
+ adoption = importlib.import_module('syncwheel_stack_adoption')
+
+ def interrupt(stage):
+ if stage == 'prepared':
+ raise RuntimeError('simulated process interruption after native adoption intent')
+
+ with (
+ self.module.manifest_write_transaction(self.repo, self.case.manifest_path),
+ mock.patch.object(adoption, 'adoption_checkpoint', side_effect=interrupt),
+ contextlib.redirect_stdout(io.StringIO()),
+ self.assertRaisesRegex(RuntimeError, 'simulated process interruption'),
+ ):
+ self.module.command_stack_set(args)
+
+ events = self.module.load_ledger_events(self.repo, self.case.manifest_path)
+ self.assertEqual(adoption.pending_adoptions(events), [plan])
+ self.assertEqual(self.case.git('status', '--porcelain'), b'')
+ selected = self.module.tracking_set_selection
+ expected_snapshots = []
+
+ def change_profile_after_first_selection(parsed):
+ selection = selected(parsed)
+ if not expected_snapshots:
+ self.assertEqual(selection[0], 'shared')
+ self.profile.write_text(json.dumps({'personal': 'review'}))
+ expected_snapshots.append(self.snapshot())
+ return selection
+
+ personal_bytes = self.personal.read_bytes()
+ stderr = io.StringIO()
+ argv = [
+ 'syncwheel', 'repo', 'tracking', 'set', 'local-only', '--apply',
+ '--repo', str(self.repo),
+ ]
+ with (
+ mock.patch.object(sys, 'argv', argv),
+ mock.patch.object(self.module, 'tracking_set_selection',
+ side_effect=change_profile_after_first_selection),
+ contextlib.redirect_stdout(io.StringIO()),
+ contextlib.redirect_stderr(stderr),
+ ):
+ result = self.module.main()
+
+ self.assertEqual(len(expected_snapshots), 1)
+ after = self.snapshot()
+ changed = [key for key in after if after[key] != expected_snapshots[0][key]]
+ self.assertEqual(changed, [], stderr.getvalue())
+ self.assertEqual(result, 2, stderr.getvalue())
+ self.assertIn('interrupted stack adoption', stderr.getvalue())
+ self.assertEqual(self.personal.read_bytes(), personal_bytes)
+ self.assertEqual(self.module.load_ledger_events(self.repo, self.personal), [])