Validate upstream sync readiness

This commit is contained in:
Meta Vens 2026-06-21 12:09:23 +01:00
commit 74cd4234c4
6 changed files with 228 additions and 28 deletions

View file

@ -84,6 +84,7 @@ fn run_smoke(args: Args) -> Result<Value> {
let item = "repo-work-readiness";
let local_verse = repo.join(".epiphany").join("local-verse.ccmp");
let work_dir = repo.join(".epiphany").join("work");
cargo_json(
&manifest,
"epiphany-repo",
@ -212,7 +213,7 @@ fn run_smoke(args: Args) -> Result<Value> {
.join(".epiphany")
.join("work")
.join(format!("work-close-{item}.json"));
cargo_json(
let publish = cargo_json(
&manifest,
"epiphany-work",
&[
@ -223,6 +224,8 @@ fn run_smoke(args: Args) -> Result<Value> {
path_str(&root)?,
"--item",
item,
"--artifact-dir",
path_str(&work_dir)?,
"--closure-receipt",
path_str(&close_receipt)?,
"--local-verse-store",
@ -250,6 +253,30 @@ fn run_smoke(args: Args) -> Result<Value> {
],
&root,
)?;
git(["branch", "-f", "main", "HEAD"], &repo)?;
let sync = cargo_json(
&manifest,
"epiphany-work",
&[
"sync",
"--workspace",
path_str(&repo)?,
"--item",
item,
"--publish-receipt",
publish
.get("receiptPath")
.and_then(Value::as_str)
.ok_or_else(|| anyhow!("publish result missing receiptPath"))?,
"--artifact-dir",
path_str(&work_dir)?,
"--upstream-ref",
"main",
"--merge-receipt",
"maintainer-merge:repo-work-readiness-smoke",
],
&root,
)?;
let deployment_aftercare_fixture = repo
.join(".epiphany")
.join("work")
@ -326,8 +353,8 @@ fn run_smoke(args: Args) -> Result<Value> {
&["schemaVersion"],
"epiphany.repo_work_readiness.v0",
)?;
require_eq(&readiness, &["status"], "not-ready")?;
require_u64(&readiness, &["missingRequiredCount"], 1)?;
require_eq(&readiness, &["status"], "ready")?;
require_u64(&readiness, &["missingRequiredCount"], 0)?;
require_bool(&readiness, &["authority", "sightOnly"], true)?;
require_bool(
&readiness,
@ -377,7 +404,15 @@ fn run_smoke(args: Args) -> Result<Value> {
require_row(&readiness, "bifrost-publication", true)?;
require_row_field_u64(&readiness, "bifrost-publication", "creditReceiptCount", 1)?;
require_row_field_u64(&readiness, "bifrost-publication", "changedPathCount", 1)?;
require_row(&readiness, "upstream-main-sync", false)?;
require_row(&readiness, "upstream-main-sync", true)?;
require_row_field_u64(&readiness, "upstream-main-sync", "mergeReceiptCount", 1)?;
require_row_field_bool(&readiness, "upstream-main-sync", "ancestryProved", true)?;
require_row_field_bool(
&readiness,
"upstream-main-sync",
"publishReceiptMatches",
true,
)?;
require_row(&readiness, "idunn-lifecycle", true)?;
require_row(&readiness, "deployment-aftercare", true)?;
require_row(&readiness, "tool-directory", true)?;
@ -417,6 +452,9 @@ fn run_smoke(args: Args) -> Result<Value> {
"branch": git_output(["branch", "--show-current"], &repo)?,
"item": item,
"publicProofOutput": public_proof["outputPath"],
"publishStatus": publish["status"],
"syncStatus": sync["status"],
"upstreamMainSynced": sync["authority"]["upstreamMainSynced"],
"readinessStatus": readiness["status"],
"missingRequiredCount": readiness["missingRequiredCount"],
"readinessVerseProjection": readiness["verseProjection"],
@ -599,6 +637,25 @@ fn require_row_field_u64(value: &Value, kind: &str, field: &str, expected: u64)
}
}
fn require_row_field_bool(value: &Value, kind: &str, field: &str, expected: bool) -> Result<()> {
let rows = value
.get("rows")
.and_then(Value::as_array)
.ok_or_else(|| anyhow!("readiness output did not include rows"))?;
let row = rows
.iter()
.find(|row| row.get("kind").and_then(Value::as_str) == Some(kind))
.ok_or_else(|| anyhow!("missing readiness row {kind:?}"))?;
let actual = row.get(field).and_then(Value::as_bool).unwrap_or(!expected);
if actual == expected {
Ok(())
} else {
Err(anyhow!(
"expected readiness row {kind:?} field {field:?} to be {expected}, got {actual}"
))
}
}
fn require_tui_row_contains(value: &Value, path: &[&str], needle: &str) -> Result<()> {
let rows = path
.iter()

View file

@ -12076,10 +12076,6 @@ fn run_readiness(args: ReadinessArgs) -> Result<Value> {
.is_some();
let publish_receipt = read_json_if_exists(&publish_receipt_path)?;
let sync_receipt = read_json_if_exists(&sync_receipt_path)?;
let upstream_synced = sync_receipt
.as_ref()
.and_then(sync_receipt_upstream_main_synced)
.unwrap_or(false);
let mut rows = vec![
readiness_path_row(
@ -12156,13 +12152,11 @@ fn run_readiness(args: ReadinessArgs) -> Result<Value> {
"Redacted public proof bundle exists.",
)?,
bifrost_publication_readiness_row(&publish_receipt_path, publish_receipt.as_ref())?,
readiness_path_row(
"upstream-main-sync",
"Bifrost/GitHub",
"epiphany.repo_work_sync.v0",
upstream_main_sync_readiness_row(
&workspace,
&sync_receipt_path,
upstream_synced,
"Published commit is contained by upstream main.",
sync_receipt.as_ref(),
publish_receipt.as_ref(),
)?,
];
let default_idunn_lifecycle_receipt = artifact_dir.join("repo-work-service-audit.json");
@ -14314,6 +14308,151 @@ fn bifrost_publication_readiness_row(path: &Path, receipt: Option<&Value>) -> Re
}))
}
fn upstream_main_sync_readiness_row(
workspace: &Path,
path: &Path,
receipt: Option<&Value>,
publish_receipt: Option<&Value>,
) -> Result<Value> {
let Some(receipt) = receipt else {
return Ok(readiness_missing_row(
"upstream-main-sync",
"Bifrost/GitHub",
"epiphany.repo_work_sync_receipt.v0 + git merge-base ancestry proof",
"Run epiphany-work sync after maintainer/Bifrost merge authority so upstream main containment is proved.",
));
};
let schema_ok = string_from_json(receipt, &["schemaVersion"]).as_deref()
== Some("epiphany.repo_work_sync_receipt.v0");
let status_synced =
string_from_json(receipt, &["status"]).as_deref() == Some("upstream-main-synced");
let upstream_main_synced =
bool_from_json(receipt, &["authority", "upstreamMainSynced"]) == Some(true)
|| bool_from_json(receipt, &["upstreamMainSynced"]) == Some(true);
let publication_authorized =
bool_from_json(receipt, &["authority", "publicationAuthorized"]) == Some(true);
let merge_authorized = bool_from_json(receipt, &["authority", "mergeAuthorized"]) == Some(true);
let private_sealed = bool_from_json(receipt, &["authority", "privateStateExposed"])
== Some(false)
&& bool_from_json(receipt, &["privateStateExposed"]).unwrap_or(false) == false;
let upstream_ref = string_from_json(receipt, &["upstreamRef"]);
let upstream_commit_sha = string_from_json(receipt, &["upstreamCommitSha"]);
let published_commit_sha = string_from_json(receipt, &["publishedCommitSha"]);
let merge_receipt_count = receipt
.get("mergeReceipts")
.and_then(Value::as_array)
.map(Vec::len)
.unwrap_or(0);
let commit_receipt_id = string_from_json(receipt, &["handsReceipts", "commitReceiptId"]);
let pr_receipt_id = string_from_json(receipt, &["handsReceipts", "prReceiptId"]);
let bifrost_publication_receipt_id =
string_from_json(receipt, &["bifrost", "publicationReceiptId"]);
let github_publication_receipt_id =
string_from_json(receipt, &["bifrost", "githubPublicationReceiptId"]);
let ledger_entry_id = string_from_json(receipt, &["bifrost", "ledgerEntryId"]);
let mut upstream_ref_resolved = false;
let mut upstream_ref_matches_receipt = false;
let mut published_commit_resolved = false;
let mut ancestry_proved = false;
if let (Some(upstream_ref), Some(upstream_commit_sha), Some(published_commit_sha)) = (
upstream_ref.as_ref(),
upstream_commit_sha.as_ref(),
published_commit_sha.as_ref(),
) {
let resolved_upstream = git_output(workspace, &["rev-parse", "--verify", upstream_ref]);
if let Ok(resolved) = resolved_upstream {
upstream_ref_resolved = true;
upstream_ref_matches_receipt = resolved == *upstream_commit_sha;
}
published_commit_resolved =
git_status_success(workspace, &["cat-file", "-e", published_commit_sha])?;
ancestry_proved = git_status_success(
workspace,
&[
"merge-base",
"--is-ancestor",
published_commit_sha,
upstream_ref,
],
)?;
}
let publish_receipt_matches = publish_receipt.is_some_and(|publish| {
string_from_json(publish, &["handsReceipts", "commitSha"]) == published_commit_sha
&& string_from_json(publish, &["handsReceipts", "commitReceiptId"]) == commit_receipt_id
&& string_from_json(publish, &["handsReceipts", "prReceiptId"]) == pr_receipt_id
&& string_from_json(publish, &["bifrost", "publicationReceiptId"])
== bifrost_publication_receipt_id
&& string_from_json(publish, &["bifrost", "githubPublicationReceiptId"])
== github_publication_receipt_id
&& string_from_json(publish, &["bifrost", "ledgerEntryId"]) == ledger_entry_id
});
let satisfied = schema_ok
&& status_synced
&& upstream_main_synced
&& publication_authorized
&& merge_authorized
&& private_sealed
&& merge_receipt_count > 0
&& upstream_ref_resolved
&& upstream_ref_matches_receipt
&& published_commit_resolved
&& ancestry_proved
&& publish_receipt_matches
&& commit_receipt_id
.as_ref()
.is_some_and(|id| !id.trim().is_empty())
&& pr_receipt_id
.as_ref()
.is_some_and(|id| !id.trim().is_empty())
&& bifrost_publication_receipt_id
.as_ref()
.is_some_and(|id| !id.trim().is_empty())
&& github_publication_receipt_id
.as_ref()
.is_some_and(|id| !id.trim().is_empty())
&& ledger_entry_id
.as_ref()
.is_some_and(|id| !id.trim().is_empty());
Ok(json!({
"kind": "upstream-main-sync",
"owner": "Bifrost/GitHub",
"requiredSchema": "epiphany.repo_work_sync_receipt.v0 + git merge-base ancestry proof",
"evidenceRef": existing_path_value(path),
"artifactStatus": if path.exists() { "present" } else { "missing" },
"schemaVersion": string_from_json(receipt, &["schemaVersion"]).unwrap_or_else(|| "missing".to_string()),
"documentStatus": string_from_json(receipt, &["status"]).unwrap_or_else(|| "missing".to_string()),
"upstreamRef": upstream_ref.unwrap_or_else(|| "missing".to_string()),
"upstreamCommitSha": upstream_commit_sha.unwrap_or_else(|| "missing".to_string()),
"publishedCommitSha": published_commit_sha.unwrap_or_else(|| "missing".to_string()),
"mergeReceiptCount": merge_receipt_count,
"commitReceiptId": commit_receipt_id.unwrap_or_else(|| "missing".to_string()),
"prReceiptId": pr_receipt_id.unwrap_or_else(|| "missing".to_string()),
"bifrostPublicationReceiptId": bifrost_publication_receipt_id.unwrap_or_else(|| "missing".to_string()),
"githubPublicationReceiptId": github_publication_receipt_id.unwrap_or_else(|| "missing".to_string()),
"ledgerEntryId": ledger_entry_id.unwrap_or_else(|| "missing".to_string()),
"upstreamMainSynced": upstream_main_synced,
"publicationAuthorized": publication_authorized,
"mergeAuthorized": merge_authorized,
"upstreamRefResolved": upstream_ref_resolved,
"upstreamRefMatchesReceipt": upstream_ref_matches_receipt,
"publishedCommitResolved": published_commit_resolved,
"ancestryProved": ancestry_proved,
"publishReceiptMatches": publish_receipt_matches,
"privateStateExposed": !private_sealed,
"satisfied": satisfied,
"status": if satisfied { "satisfied" } else { "missing" },
"note": "Sync receipt proves the published commit is contained by the named upstream ref after maintainer/Bifrost merge authority.",
"readinessApprovalAuthorized": false,
"serviceLifecycleAuthority": false,
"handsActionAuthorized": false
}))
}
fn idunn_lifecycle_readiness_row(path: &Path) -> Result<Value> {
let document = read_json_if_exists(path)?;
let schema_version = document