fix(provenance): report non-zero git status exits and update bootstrap rebuild hint

- Update get_local_checkout_status in scripts/provenance.py to surface non-zero git status exit codes as '⚠️ Git Error (exit <code>)' rather than masking them as '✓ Clean'
- Update scripts/bootstrap_token.py rebuild instruction to use path:$HOME/Core#server --impure, ensuring instance.nix evaluation is respected
- Add unit test coverage for non-zero git exit handling and bootstrap rebuild guidance
This commit is contained in:
kiskaadee committed 2026-10-30 13:40:22 -05:00
1 parent e2dbc97b0e
commit 4f1a63160b
4 files changed
+28 -3

No files matched your search

+1 -1
View File
@@ -163,7 +163,7 @@ def main(argv: list[str] | None = None) -> int:
f"Add the following descriptor to your SOPS tokens store (nixos/secrets.yaml -> appctl/tokens_json):\n\n" f"Add the following descriptor to your SOPS tokens store (nixos/secrets.yaml -> appctl/tokens_json):\n\n"
f"{json_snippet}\n\n" f"{json_snippet}\n\n"
f"After updating nixos/secrets.yaml with `sops nixos/secrets.yaml`, apply changes with:\n" f"After updating nixos/secrets.yaml with `sops nixos/secrets.yaml`, apply changes with:\n"
f" sudo nixos-rebuild switch --flake ~/Core#server\n" f" sudo nixos-rebuild switch --flake path:$HOME/Core#server --impure\n"
) )
return 0 return 0
+10 -2
View File
@@ -109,6 +109,7 @@ def get_local_checkout_status(dir_path: Path | str) -> CheckoutStatus:
# 1. Check cleanliness # 1. Check cleanliness
is_dirty = False is_dirty = False
git_error: str | None = None
try: try:
status_res = subprocess.run( status_res = subprocess.run(
["git", "-C", str(path), "status", "--porcelain"], ["git", "-C", str(path), "status", "--porcelain"],
@@ -118,10 +119,14 @@ def get_local_checkout_status(dir_path: Path | str) -> CheckoutStatus:
timeout=5.0, timeout=5.0,
env=git_env, env=git_env,
) )
if status_res.returncode == 0 and status_res.stdout.strip(): if status_res.returncode == 0:
if status_res.stdout.strip():
is_dirty = True is_dirty = True
except (subprocess.SubprocessError, OSError): else:
git_error = f"⚠️ Git Error (exit {status_res.returncode})"
except (subprocess.SubprocessError, OSError) as exc:
is_dirty = False is_dirty = False
git_error = f"⚠️ Git Error ({exc.__class__.__name__})"
# 2. Get active branch # 2. Get active branch
branch = "" branch = ""
@@ -168,6 +173,9 @@ def get_local_checkout_status(dir_path: Path | str) -> CheckoutStatus:
commit_sha = "" commit_sha = ""
# 4. Format status label # 4. Format status label
if git_error:
status_label = git_error
else:
state_symbol = "* Dirty" if is_dirty else "✓ Clean" state_symbol = "* Dirty" if is_dirty else "✓ Clean"
ref_desc = f"{branch}@{commit_sha}" if commit_sha else branch ref_desc = f"{branch}@{commit_sha}" if commit_sha else branch
status_label = f"{state_symbol} ({ref_desc})" if ref_desc else state_symbol status_label = f"{state_symbol} ({ref_desc})" if ref_desc else state_symbol
+1
View File
@@ -126,6 +126,7 @@ def test_bootstrap_cli_never_prints_raw_secret_to_stdout_or_stderr(
# Ensure stdout provides helpful human guidance # Ensure stdout provides helpful human guidance
assert "operator-admin" in captured.out assert "operator-admin" in captured.out
assert "sops nixos/secrets.yaml" in captured.out assert "sops nixos/secrets.yaml" in captured.out
assert "sudo nixos-rebuild switch --flake path:$HOME/Core#server --impure" in captured.out
def test_bootstrap_cli_print_json_outputs_valid_json_descriptor( def test_bootstrap_cli_print_json_outputs_valid_json_descriptor(
+16
View File
@@ -250,3 +250,19 @@ def test_resolve_upstream_provenance_class_b_and_default_timeout():
prov = resolve_upstream_provenance(source, local_commit="abc1234") prov = resolve_upstream_provenance(source, local_commit="abc1234")
assert prov.status == ProvenanceStatus.SYNCED assert prov.status == ProvenanceStatus.SYNCED
assert mock_run.call_args[1]["timeout"] == 10.0 assert mock_run.call_args[1]["timeout"] == 10.0
def test_get_local_checkout_status_git_error(tmp_path: Path):
app_dir = tmp_path / "git_error_app"
app_dir.mkdir()
(app_dir / ".git").mkdir()
with patch("subprocess.run") as mock_run:
mock_run.return_value = MagicMock(
returncode=128, stdout="", stderr="fatal: dubious ownership"
)
status = get_local_checkout_status(app_dir)
assert status.is_git is True
assert status.is_dirty is False
assert status.status_label == "⚠️ Git Error (exit 128)"