Skip to content

Commit 6e7e1c3

Browse files
committed
fix(sync): treat repo_state_sync as derived state; allow clean repo bootstrap
1 parent fe87c43 commit 6e7e1c3

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/shieldcraft/services/sync/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,21 @@ def verify_repo_state_authoritative(repo_root: str = ".") -> Dict[str, str]:
162162

163163
# 'repo_state_sync' mode: verify external repo_state_sync.json and associated artifacts
164164
if authority == "repo_state_sync":
165-
res = verify_repo_sync(repo_root)
166-
res["authority"] = "repo_state_sync"
167-
return res
165+
# Treat repo_state_sync as derived state (non-mandatory):
166+
# If the external sync artifact is present, validate it; if it is
167+
# missing, allow the run to proceed (do not raise SyncError).
168+
try:
169+
res = verify_repo_sync(repo_root)
170+
res["authority"] = "repo_state_sync"
171+
return res
172+
except Exception as e:
173+
# If it's a SyncError due to missing artifact, relax and proceed;
174+
# otherwise re-raise to preserve strict failure modes for other errors.
175+
from inspect import getmodule
176+
# Detect SyncError by attribute presence (class imported above)
177+
if getattr(e, "code", None) == SYNC_MISSING:
178+
return {"ok": True, "authority": "repo_state_sync", "artifact": None}
179+
raise
168180

169181
# Snapshot-based authority (opt-in only)
170182
from shieldcraft.snapshot import validate_snapshot, generate_snapshot, DEFAULT_SNAPSHOT_PATH, SnapshotError

tests/ci/test_v1_invariants.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44

55
def test_snapshot_authority_is_default(monkeypatch, tmp_path):
6-
from shieldcraft.services.sync import verify_repo_state_authoritative, SyncError
6+
from shieldcraft.services.sync import verify_repo_state_authoritative
77

88
# Unset any explicit authority and ensure repo_state_sync is used by default
99
monkeypatch.delenv('SHIELDCRAFT_SYNC_AUTHORITY', raising=False)
1010
monkeypatch.delenv('SHIELDCRAFT_ALLOW_EXTERNAL_SYNC', raising=False)
1111

12-
# In a fresh tmp dir with no repo_state_sync artifact, default mode should raise SyncError
13-
with pytest.raises(SyncError):
14-
verify_repo_state_authoritative(str(tmp_path))
12+
# In a fresh tmp dir with no repo_state_sync artifact, default mode should NOT raise
13+
assert verify_repo_state_authoritative(str(tmp_path)).get("ok") is True
1514

1615

1716
def test_external_requires_explicit_opt_in(monkeypatch, tmp_path):

0 commit comments

Comments
 (0)