utopia-ia/elffuss-braid public
Changesets · Branches · Tags · Compare
| Changeset | 9cd050413e8ec3a673d839579a54c37caae909332ca0bac542cf4c6796e9d70d |
|---|---|
| Author | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-22 17:10 +02:00 |
| Committer | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-22 17:10 +02:00 |
| Parents | e37ee20e4c7f |
11 files changed
modified crates/cli/src/hub/fetch.rs +74 −2
| @@ -12,7 +12,9 @@ | ||
| 12 | 12 | //! changesets the hub does not have stays where it is, and is reported. A |
| 13 | 13 | //! tag is created, and never moved. `remote/hub/<ref>` records where each |
| 14 | 14 | //! of the hub's refs was seen, so that a branch kept back still has a name |
| 15 | -//! for the hub's head. | |
| 15 | +//! for the hub's head. Of the hub's own refs, only `braid/green/<branch>` | |
| 16 | +//! and `braid/red/<branch>` are recorded so, when the store holds what they | |
| 17 | +//! name: they say how the hub verifies a branch, and are never carried. | |
| 16 | 18 | |
| 17 | 19 | use std::cell::RefCell; |
| 18 | 20 | use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; |
| @@ -23,6 +25,7 @@ | ||
| 23 | 25 | use braid_format::tree::{EntryKind, Node}; |
| 24 | 26 | use braid_format::{Kind, ObjectId, Objects, Signature}; |
| 25 | 27 | use braid_hubproto::api::MissingRequest; |
| 28 | +use braid_hubproto::verify::{GREEN_PREFIX, RED_PREFIX}; | |
| 26 | 29 | use braid_repo::{Repo, RepoHistory}; |
| 27 | 30 | use braid_store::{RefUpdate, Refs, Store, TransactError}; |
| 28 | 31 | |
| @@ -49,6 +52,13 @@ | ||
| 49 | 52 | braid_repo::is_branch(name) || is_tag(name) |
| 50 | 53 | } |
| 51 | 54 | |
| 55 | +/// Whether a hub ref says how the hub verifies a branch (section 25 of | |
| 56 | +/// `docs/hub.md`): `braid/green/<branch>` or `braid/red/<branch>`. Never | |
| 57 | +/// carried, it is only recorded where it was seen. | |
| 58 | +pub(crate) fn is_verdict(name: &str) -> bool { | |
| 59 | + name.starts_with(GREEN_PREFIX) || name.starts_with(RED_PREFIX) | |
| 60 | +} | |
| 61 | + | |
| 52 | 62 | /// What became of a local ref. |
| 53 | 63 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 54 | 64 | pub(crate) enum Outcome { |
| @@ -505,11 +515,26 @@ | ||
| 505 | 515 | Err(err) => return Err(err), |
| 506 | 516 | } |
| 507 | 517 | |
| 518 | + // How the hub verifies its branches, where the store holds what its | |
| 519 | + // refs name: a changeset of a branch, which the branch brought. | |
| 520 | + let mut verdicts: Vec<(String, ObjectId)> = Vec::new(); | |
| 521 | + for (name, id) in hub.refs.iter().filter(|(name, _)| is_verdict(name)) { | |
| 522 | + if holds_changeset(store, id)? { | |
| 523 | + verdicts.push((name.clone(), *id)); | |
| 524 | + } | |
| 525 | + } | |
| 526 | + | |
| 508 | 527 | let mut history = repo.history(); |
| 509 | 528 | let mut decided = Vec::new(); |
| 510 | 529 | let description = format!("hub fetch {} from {}", link.repo, link.url); |
| 511 | 530 | let result = store.transact_with(agent, |current| -> Result<_, Option<anyhow::Error>> { |
| 512 | 531 | let mut updates = Vec::new(); |
| 532 | + for (name, id) in &verdicts { | |
| 533 | + let seen = remote_ref(name); | |
| 534 | + if current.get(&seen) != Some(*id) { | |
| 535 | + updates.push(RefUpdate::new(seen.clone(), current.get(&seen), Some(*id))); | |
| 536 | + } | |
| 537 | + } | |
| 513 | 538 | for (name, hub_head) in &carried { |
| 514 | 539 | let before = current.get(name); |
| 515 | 540 | let outcome = match skipped.get(name) { |
| @@ -542,11 +567,12 @@ | ||
| 542 | 567 | }); |
| 543 | 568 | } |
| 544 | 569 | // A ref the hub no longer has, or that cannot be carried, has no |
| 545 | - // place where it was seen. | |
| 570 | + // place where it was seen, unless it says how a branch is verified. | |
| 546 | 571 | for (name, id) in current.iter() { |
| 547 | 572 | if let Some(rest) = name.strip_prefix(REMOTE_PREFIX) |
| 548 | 573 | && (!carried.iter().any(|(carried, _)| carried == rest) |
| 549 | 574 | || skipped.contains_key(rest)) |
| 575 | + && !verdicts.iter().any(|(verdict, _)| verdict == rest) | |
| 550 | 576 | { |
| 551 | 577 | updates.push(RefUpdate::new(name, Some(id), None)); |
| 552 | 578 | } |
| @@ -726,6 +752,52 @@ | ||
| 726 | 752 | assert_eq!(outcome(&fourth, "behind"), Outcome::Diverged); |
| 727 | 753 | } |
| 728 | 754 | |
| 755 | + #[test] | |
| 756 | + fn the_hubs_green_and_red_are_recorded_where_they_were_seen() { | |
| 757 | + let hub = FakeHub::new(); | |
| 758 | + let local = Fixture::linked(&hub); | |
| 759 | + let root = ada_change(&hub.repo, None, &[("a.txt", "a\n")]); | |
| 760 | + let two = ada_change(&hub.repo, Some(root), &[("b.txt", "b\n")]); | |
| 761 | + set_ref(&hub.repo, "main", two); | |
| 762 | + set_ref(&hub.repo, "braid/green/main", root); | |
| 763 | + set_ref(&hub.repo, "braid/red/main", two); | |
| 764 | + // One that names what the hub's branches do not bring is not | |
| 765 | + // recorded: the store would not hold what it names. | |
| 766 | + let elsewhere = ada_change(&hub.repo, None, &[("z.txt", "z\n")]); | |
| 767 | + set_ref(&hub.repo, "braid/green/gone", elsewhere); | |
| 768 | + | |
| 769 | + let first = fetch(&local.repo, &hub, &local.link, "tester", None).unwrap(); | |
| 770 | + let refs = local.repo.store().refs().unwrap(); | |
| 771 | + assert_eq!(refs.get("remote/hub/braid/green/main"), Some(root)); | |
| 772 | + assert_eq!(refs.get("remote/hub/braid/red/main"), Some(two)); | |
| 773 | + assert_eq!(refs.get("remote/hub/braid/green/gone"), None); | |
| 774 | + // They are never carried, nor reported as branches. | |
| 775 | + assert_eq!(refs.get("braid/green/main"), None); | |
| 776 | + assert_eq!(refs.get("braid/red/main"), None); | |
| 777 | + assert!(first.refs.iter().all(|r| !r.name.starts_with("braid/"))); | |
| 778 | + assert_eq!(first.hub_refs.get("braid/red/main"), Some(&two)); | |
| 779 | + | |
| 780 | + // Red cleared and green moved on the hub: the next fetch follows, | |
| 781 | + // and nothing else moves. | |
| 782 | + hub.repo | |
| 783 | + .store() | |
| 784 | + .transact("tester", "verify", |refs| { | |
| 785 | + Ok::<_, std::convert::Infallible>(vec![ | |
| 786 | + RefUpdate::new("braid/red/main", refs.get("braid/red/main"), None), | |
| 787 | + RefUpdate::new("braid/green/main", refs.get("braid/green/main"), Some(two)), | |
| 788 | + ]) | |
| 789 | + }) | |
| 790 | + .unwrap(); | |
| 791 | + let second = fetch(&local.repo, &hub, &local.link, "tester", None).unwrap(); | |
| 792 | + assert!(second.operation.is_some()); | |
| 793 | + let refs = local.repo.store().refs().unwrap(); | |
| 794 | + assert_eq!(refs.get("remote/hub/braid/green/main"), Some(two)); | |
| 795 | + assert_eq!(refs.get("remote/hub/braid/red/main"), None); | |
| 796 | + assert_eq!(refs.get("main"), Some(two)); | |
| 797 | + let third = fetch(&local.repo, &hub, &local.link, "tester", None).unwrap(); | |
| 798 | + assert_eq!(third.operation, None); | |
| 799 | + } | |
| 800 | + | |
| 729 | 801 | #[test] |
| 730 | 802 | fn tags_that_name_no_changeset_are_skipped() { |
| 731 | 803 | let hub = FakeHub::new(); |
modified crates/cli/src/hub/land.rs +27 −0
| @@ -522,6 +522,33 @@ | ||
| 522 | 522 | assert_eq!(s.hub.called("land"), lands); |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | + #[test] | |
| 526 | + fn a_landing_reports_what_the_hub_says_of_the_branch() { | |
| 527 | + let s = Setup::new(); | |
| 528 | + let ws = s.workspace("w1"); | |
| 529 | + let mine = edit_and_commit(&ws, "c.txt", "c\n"); | |
| 530 | + s.hub.verify.borrow_mut().landing = Some(braid_hubproto::verify::LandVerify { | |
| 531 | + state: braid_hubproto::verify::STATE_RED.to_owned(), | |
| 532 | + green: None, | |
| 533 | + red: Some(mine), | |
| 534 | + culprit: Some(mine), | |
| 535 | + reverted: Vec::new(), | |
| 536 | + }); | |
| 537 | + let landing = s.land(&ws).unwrap(); | |
| 538 | + let report = crate::work::Report::hub(landing.response.as_ref().unwrap()); | |
| 539 | + let json = report.json(); | |
| 540 | + assert_eq!(json["hub_verify"]["state"], "red"); | |
| 541 | + assert_eq!(json["hub_verify"]["culprit"], mine.to_hex()); | |
| 542 | + assert_eq!(json["hub_verify"]["reverted"], serde_json::json!([])); | |
| 543 | + // A hub that says nothing of the branch: null. | |
| 544 | + s.hub.verify.borrow_mut().landing = None; | |
| 545 | + let two = edit_and_commit(&ws, "d.txt", "d\n"); | |
| 546 | + let landing = s.land(&ws).unwrap(); | |
| 547 | + let report = crate::work::Report::hub(landing.response.as_ref().unwrap()); | |
| 548 | + assert_eq!(report.head, Some(two)); | |
| 549 | + assert_eq!(report.json()["hub_verify"], serde_json::Value::Null); | |
| 550 | + } | |
| 551 | + | |
| 525 | 552 | #[test] |
| 526 | 553 | fn a_rebase_on_the_hub_brings_the_others_work_into_the_workspace() { |
| 527 | 554 | let s = Setup::new(); |
modified crates/cli/src/hub/mod.rs +19 −3
| @@ -155,7 +155,10 @@ | ||
| 155 | 155 | tag is created, and never moved. remote/hub/<ref> records where each of the |
| 156 | 156 | hub's refs was seen, so `braid log remote/hub/main` shows the hub's main |
| 157 | 157 | even when the local one was kept back. Tags that name no changeset are |
| 158 | -skipped: the hub protocol carries changesets only. | |
| 158 | +skipped: the hub protocol carries changesets only. Of the hub's own refs, | |
| 159 | +only braid/green/<branch> and braid/red/<branch>, which say how the hub | |
| 160 | +verifies a branch, are recorded so (remote/hub/braid/green/<branch>), and | |
| 161 | +`braid status --json` gives them as hub_green and hub_red. | |
| 159 | 162 | |
| 160 | 163 | `braid land` and `braid update` fetch by themselves in a linked repository. |
| 161 | 164 | |
| @@ -177,10 +180,14 @@ | ||
| 177 | 180 | branch, and how the last sync ended: diverged means someone pushed to the |
| 178 | 181 | mirror directly, and the hub's owner takes those commits in on the hub. |
| 179 | 182 | |
| 183 | +A branch the hub verifies shows its green, the newest changeset with a pass | |
| 184 | +the hub accepts, and while the hub holds it red, its red (`braid hub verify | |
| 185 | +status` says more). | |
| 186 | + | |
| 180 | 187 | With --json it prints hub, repo, paths, login (null when not signed in), |
| 181 | 188 | token (environment, file or null), mirror (url, last_sync, outcome and |
| 182 | 189 | detail, or null), seq (the hub's op log sequence number) and branches, each |
| 183 | -with name, local, hub and state."; | |
| 190 | +with name, local, hub, state, green and red (null when the hub has none)."; | |
| 184 | 191 | |
| 185 | 192 | /// The long help of `hub whoami`. |
| 186 | 193 | pub(crate) const WHOAMI_HELP: &str = |
| @@ -1216,6 +1223,8 @@ | ||
| 1216 | 1223 | "local": hex(s.local), |
| 1217 | 1224 | "hub": hex(s.hub), |
| 1218 | 1225 | "state": s.state.code(), |
| 1226 | + "green": hex(s.green), | |
| 1227 | + "red": hex(s.red), | |
| 1219 | 1228 | })).collect::<Vec<_>>(), |
| 1220 | 1229 | }))?; |
| 1221 | 1230 | return Ok(ExitCode::SUCCESS); |
| @@ -1258,10 +1267,17 @@ | ||
| 1258 | 1267 | } |
| 1259 | 1268 | } |
| 1260 | 1269 | for s in &states { |
| 1261 | - let heads = match (s.local, s.hub) { | |
| 1270 | + let mut heads = match (s.local, s.hub) { | |
| 1262 | 1271 | (Some(here), Some(there)) if here == there => here.short(), |
| 1263 | 1272 | (here, there) => format!("here {}, hub {}", short(here), short(there)), |
| 1264 | 1273 | }; |
| 1274 | + // How the hub verifies it, when it does. | |
| 1275 | + if let Some(red) = s.red { | |
| 1276 | + heads.push_str(&format!(", red at {}", red.short())); | |
| 1277 | + } | |
| 1278 | + if let Some(green) = s.green { | |
| 1279 | + heads.push_str(&format!(", green at {}", green.short())); | |
| 1280 | + } | |
| 1265 | 1281 | println!( |
| 1266 | 1282 | " {:<24} {:<9} {heads}", |
| 1267 | 1283 | remote::shown(&s.name), |
modified crates/cli/src/hub/request.rs +10 −1
| @@ -59,6 +59,7 @@ | ||
| 59 | 59 | CONFLICTS, REFUSED, agent, body_text, exit_for, idempotency_key, print, |
| 60 | 60 | }; |
| 61 | 61 | use super::transfer::store_stream; |
| 62 | +use super::verify::land_note; | |
| 62 | 63 | use crate::work::count; |
| 63 | 64 | use crate::{Cli, open_repo, print_json}; |
| 64 | 65 | |
| @@ -203,7 +204,9 @@ | ||
| 203 | 204 | " |
| 204 | 205 | |
| 205 | 206 | With --json it prints {request, land}: the request as it is now, and the |
| 206 | -landing as `POST …/land` answers it." | |
| 207 | +landing as `POST …/land` answers it, with verify when the hub verifies the | |
| 208 | +base. While the hub holds the base red, braid also says so on standard | |
| 209 | +error, as `braid land` does." | |
| 207 | 210 | ); |
| 208 | 211 | |
| 209 | 212 | /// The long help of `hub request checkout`. |
| @@ -1897,6 +1900,12 @@ | ||
| 1897 | 1900 | print(cli, &serde_json::to_value(&landed)?, || { |
| 1898 | 1901 | landed_text(target, number, &landed) |
| 1899 | 1902 | })?; |
| 1903 | + // The base, red on a hub that verifies it, as `braid land` says. | |
| 1904 | + if let Some(verify) = &landed.land.verify | |
| 1905 | + && let Some(note) = land_note(&landed.land.reference, verify, Some(target)) | |
| 1906 | + { | |
| 1907 | + eprintln!("braid: {note}"); | |
| 1908 | + } | |
| 1900 | 1909 | Ok(code) |
| 1901 | 1910 | } |
| 1902 | 1911 |
modified crates/cli/src/hub/status.rs +18 −1
| @@ -2,12 +2,13 @@ | ||
| 2 | 2 | // Copyright (c) 2026 UtopiaIA |
| 3 | 3 | |
| 4 | 4 | //! How each branch of a linked repository compares with the hub's, for |
| 5 | -//! `braid hub status`. | |
| 5 | +//! `braid hub status`, and how the hub verifies it: its green and its red. | |
| 6 | 6 | |
| 7 | 7 | use std::collections::{BTreeMap, BTreeSet}; |
| 8 | 8 | |
| 9 | 9 | use anyhow::Result; |
| 10 | 10 | use braid_format::{Kind, ObjectId, Objects}; |
| 11 | +use braid_hubproto::verify::{green_ref, red_ref}; | |
| 11 | 12 | use braid_repo::Repo; |
| 12 | 13 | |
| 13 | 14 | use super::fetch::remote_ref; |
| @@ -50,6 +51,11 @@ | ||
| 50 | 51 | pub(crate) hub: Option<ObjectId>, |
| 51 | 52 | /// How they compare. |
| 52 | 53 | pub(crate) state: State, |
| 54 | + /// The hub's green of the branch, when it verifies the branch: the | |
| 55 | + /// newest changeset with a pass it accepts. | |
| 56 | + pub(crate) green: Option<ObjectId>, | |
| 57 | + /// The hub's red of the branch, while it holds the branch red. | |
| 58 | + pub(crate) red: Option<ObjectId>, | |
| 53 | 59 | } |
| 54 | 60 | |
| 55 | 61 | /// Compares every branch of `repo` and of the hub, whose refs are `hub`. |
| @@ -105,6 +111,8 @@ | ||
| 105 | 111 | local: here, |
| 106 | 112 | hub: there, |
| 107 | 113 | state, |
| 114 | + green: hub.get(&green_ref(name)).copied(), | |
| 115 | + red: hub.get(&red_ref(name)).copied(), | |
| 108 | 116 | }); |
| 109 | 117 | } |
| 110 | 118 | history.flush()?; |
| @@ -145,6 +153,9 @@ | ||
| 145 | 153 | ("moved", unknown), |
| 146 | 154 | ("lost", unknown), |
| 147 | 155 | ("tags/v1", two), |
| 156 | + // The hub verifies `behind`: green at root, red at two. | |
| 157 | + ("braid/green/behind", root), | |
| 158 | + ("braid/red/behind", two), | |
| 148 | 159 | ] |
| 149 | 160 | .into_iter() |
| 150 | 161 | .map(|(name, id)| (name.to_owned(), id)) |
| @@ -164,5 +175,11 @@ | ||
| 164 | 175 | ("same", State::Same), |
| 165 | 176 | ] |
| 166 | 177 | ); |
| 178 | + let verified: Vec<(&str, Option<ObjectId>, Option<ObjectId>)> = states | |
| 179 | + .iter() | |
| 180 | + .filter(|s| s.green.is_some() || s.red.is_some()) | |
| 181 | + .map(|s| (s.name.as_str(), s.green, s.red)) | |
| 182 | + .collect(); | |
| 183 | + assert_eq!(verified, [("behind", Some(root), Some(two))]); | |
| 167 | 184 | } |
| 168 | 185 | } |
modified crates/cli/src/hub/testing.rs +8 −2
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | }; |
| 20 | 20 | use braid_hubproto::stream; |
| 21 | 21 | use braid_hubproto::verify::{ |
| 22 | - self as verify, ReportPolicy, VerifyEvent, VerifyPolicy, VerifyReport, VerifyReset, | |
| 22 | + self as verify, LandVerify, ReportPolicy, VerifyEvent, VerifyPolicy, VerifyReport, VerifyReset, | |
| 23 | 23 | VerifyStatus, |
| 24 | 24 | }; |
| 25 | 25 | use braid_repo::Repo; |
| @@ -349,7 +349,10 @@ | ||
| 349 | 349 | agent, |
| 350 | 350 | &committer, |
| 351 | 351 | ) { |
| 352 | - Ok(report) => Ok(response(&report)), | |
| 352 | + Ok(report) => Ok(LandResponse { | |
| 353 | + verify: self.verify.borrow().landing.clone(), | |
| 354 | + ..response(&report) | |
| 355 | + }), | |
| 353 | 356 | Err(braid_wc::Error::NotOnBranch { .. }) => Err(HubError::api( |
| 354 | 357 | 409, |
| 355 | 358 | "not_on_branch", |
| @@ -412,6 +415,8 @@ | ||
| 412 | 415 | pub(crate) lose: usize, |
| 413 | 416 | /// What every call answers instead, while it is set. |
| 414 | 417 | pub(crate) refuse: Option<Refusal>, |
| 418 | + /// What the answers of landings say of the branch, as `verify`. | |
| 419 | + pub(crate) landing: Option<LandVerify>, | |
| 415 | 420 | /// The answers given, by key: the same key gets the same answer. |
| 416 | 421 | answers: HashMap<String, Value>, |
| 417 | 422 | } |
| @@ -429,6 +434,7 @@ | ||
| 429 | 434 | verdicts: Vec::new(), |
| 430 | 435 | lose: 0, |
| 431 | 436 | refuse: None, |
| 437 | + landing: None, | |
| 432 | 438 | answers: HashMap::new(), |
| 433 | 439 | } |
| 434 | 440 | } |
modified crates/cli/src/hub/verify.rs +61 −1
| @@ -30,7 +30,7 @@ | ||
| 30 | 30 | use braid_hubproto::RepoPath; |
| 31 | 31 | use braid_hubproto::names::is_owner; |
| 32 | 32 | use braid_hubproto::verify::{ |
| 33 | - FEATURE, MAX_REPORTERS, MODE_OFF, MODE_REPORT, SOURCE_REPORT, STATE_OFF, STATE_RED, | |
| 33 | + FEATURE, LandVerify, MAX_REPORTERS, MODE_OFF, MODE_REPORT, SOURCE_REPORT, STATE_OFF, STATE_RED, | |
| 34 | 34 | STATE_STUCK, VerifyEvents, VerifyPolicy, VerifyReport, VerifyReportAnswer, VerifyReset, |
| 35 | 35 | VerifyStatus, is_git_commit, is_suite, |
| 36 | 36 | }; |
| @@ -833,6 +833,30 @@ | ||
| 833 | 833 | out.trim_end().to_owned() |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | +/// What braid notes on standard error after a landing whose answer says | |
| 837 | +/// that `branch` is red: one line, or `None` when there is nothing to say. | |
| 838 | +/// `repo`, when given, is the repository to name with `-R` in the hint. | |
| 839 | +pub(crate) fn land_note( | |
| 840 | + branch: &str, | |
| 841 | + verify: &LandVerify, | |
| 842 | + repo: Option<&RepoPath>, | |
| 843 | +) -> Option<String> { | |
| 844 | + if !is_red(&verify.state) { | |
| 845 | + return None; | |
| 846 | + } | |
| 847 | + let blame = match (verify.culprit, verify.red) { | |
| 848 | + (Some(culprit), _) => format!(", culprit {}", culprit.short()), | |
| 849 | + (None, Some(red)) => format!(" at {}, no culprit named", red.short()), | |
| 850 | + (None, None) => String::new(), | |
| 851 | + }; | |
| 852 | + let flag = repo.map_or_else(String::new, |repo| format!(" -R {repo}")); | |
| 853 | + Some(format!( | |
| 854 | + "note: {} is {} on the hub{blame}: `braid hub verify status{flag}` says more", | |
| 855 | + shown(branch), | |
| 856 | + shown(&verify.state) | |
| 857 | + )) | |
| 858 | +} | |
| 859 | + | |
| 836 | 860 | #[cfg(test)] |
| 837 | 861 | mod tests { |
| 838 | 862 | use super::*; |
| @@ -1416,4 +1440,40 @@ | ||
| 1416 | 1440 | Asked::Status { fail_on_red: true } |
| 1417 | 1441 | )); |
| 1418 | 1442 | } |
| 1443 | + | |
| 1444 | + #[test] | |
| 1445 | + fn a_landing_on_a_red_branch_says_so() { | |
| 1446 | + let id = ObjectId::hash(braid_format::Kind::Changeset, b"x"); | |
| 1447 | + let mut verify = LandVerify { | |
| 1448 | + state: STATE_RED.into(), | |
| 1449 | + green: None, | |
| 1450 | + red: Some(id), | |
| 1451 | + culprit: Some(id), | |
| 1452 | + reverted: Vec::new(), | |
| 1453 | + }; | |
| 1454 | + let note = land_note("main", &verify, None).unwrap(); | |
| 1455 | + assert_eq!( | |
| 1456 | + note, | |
| 1457 | + format!( | |
| 1458 | + "note: main is red on the hub, culprit {}: `braid hub verify status` says more", | |
| 1459 | + id.short() | |
| 1460 | + ) | |
| 1461 | + ); | |
| 1462 | + verify.culprit = None; | |
| 1463 | + verify.state = STATE_STUCK.into(); | |
| 1464 | + let note = land_note("main", &verify, Some(&path())).unwrap(); | |
| 1465 | + assert!(note.contains("is stuck on the hub at"), "{note}"); | |
| 1466 | + assert!( | |
| 1467 | + note.ends_with("`braid hub verify status -R ada/demo` says more"), | |
| 1468 | + "{note}" | |
| 1469 | + ); | |
| 1470 | + for state in [STATE_GREEN, STATE_PENDING, "unknown", "later"] { | |
| 1471 | + verify.state = state.into(); | |
| 1472 | + assert_eq!(land_note("main", &verify, None), None, "{state}"); | |
| 1473 | + } | |
| 1474 | + // What the hub says is shown, never raw. | |
| 1475 | + verify.state = STATE_RED.into(); | |
| 1476 | + let note = land_note("ma\u{1b}in", &verify, None).unwrap(); | |
| 1477 | + assert!(!note.contains('\u{1b}'), "{note}"); | |
| 1478 | + } | |
| 1419 | 1479 | } |
modified crates/cli/src/revert.rs +3 −0
| @@ -160,6 +160,9 @@ | ||
| 160 | 160 | )?) |
| 161 | 161 | }; |
| 162 | 162 | let code = report.as_ref().map_or(ExitCode::SUCCESS, Report::exit_code); |
| 163 | + if let Some(report) = &report { | |
| 164 | + report.note_red(); | |
| 165 | + } | |
| 163 | 166 | if cli.json { |
| 164 | 167 | print_json(&json!({ |
| 165 | 168 | "revert": change.to_hex(), |
modified crates/cli/src/work.rs +38 −5
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | use braid_engine::{Conflict, ConflictKind, HunkSide}; |
| 17 | 17 | use braid_format::{ChangeOp, EntryKind, ObjectId}; |
| 18 | 18 | use braid_hubproto::api::LandResponse; |
| 19 | +use braid_hubproto::verify::LandVerify; | |
| 19 | 20 | use braid_repo::{Location, Repo}; |
| 20 | 21 | use braid_store::Refs; |
| 21 | 22 | use braid_wc::{ |
| @@ -69,6 +70,11 @@ | ||
| 69 | 70 | new change create on the branch after change create; |
| 70 | 71 | otherwise null. It repeats the --repo, --agent and |
| 71 | 72 | --workspace given on the command line |
| 73 | + hub_verify after a landing on a hub that verifies the branch, how | |
| 74 | + the hub says it stands: {state, green, red, culprit, | |
| 75 | + reverted}, as `braid hub verify --help` describes them; | |
| 76 | + otherwise null. While it is red or stuck, braid also | |
| 77 | + says so on standard error | |
| 72 | 78 | |
| 73 | 79 | Ids in JSON are full; text output shows their first 12 hex digits." |
| 74 | 80 | }; |
| @@ -86,6 +92,13 @@ | ||
| 86 | 92 | head the branch's head, or null when the branch does not exist |
| 87 | 93 | green the newest changeset of the branch that passed `braid |
| 88 | 94 | verify`, braid/green/<branch>, or null |
| 95 | + hub_green in a repository linked to a hub that verifies the | |
| 96 | + branch, the hub's green as the last fetch saw it: the | |
| 97 | + newest changeset of the branch with a pass the hub | |
| 98 | + accepts; otherwise null | |
| 99 | + hub_red the hub's red as the last fetch saw it: while the hub | |
| 100 | + holds the branch red, the changeset it blames, or the | |
| 101 | + first fail it cannot explain; otherwise null | |
| 89 | 102 | behind whether the branch has changesets the workspace does not |
| 90 | 103 | behind_by how many: the changesets from the branch's head down to |
| 91 | 104 | the one the workspace's own start from, along first |
| @@ -566,11 +579,10 @@ | ||
| 566 | 579 | })).collect::<Vec<_>>(), |
| 567 | 580 | }) |
| 568 | 581 | }); |
| 569 | - let green = target | |
| 570 | - .repo | |
| 571 | - .store() | |
| 572 | - .refs()? | |
| 573 | - .get(&crate::verify::green_ref(&state.branch)); | |
| 582 | + let refs = target.repo.store().refs()?; | |
| 583 | + let green = refs.get(&crate::verify::green_ref(&state.branch)); | |
| 584 | + // Where a fetch last saw the hub's own refs of the branch. | |
| 585 | + let seen = |name: String| hex(refs.get(&hub::fetch::remote_ref(&name))); | |
| 574 | 586 | print_json(&json!({ |
| 575 | 587 | "workspace": workspace.name(), |
| 576 | 588 | "path": workspace.dir().to_string_lossy(), |
| @@ -578,6 +590,8 @@ | ||
| 578 | 590 | "base": hex(state.base), |
| 579 | 591 | "head": hex(report.head), |
| 580 | 592 | "green": hex(green), |
| 593 | + "hub_green": seen(braid_hubproto::verify::green_ref(&state.branch)), | |
| 594 | + "hub_red": seen(braid_hubproto::verify::red_ref(&state.branch)), | |
| 581 | 595 | "behind": report.behind(), |
| 582 | 596 | "behind_by": report.behind_by, |
| 583 | 597 | "clean": status.is_clean(), |
| @@ -790,6 +804,8 @@ | ||
| 790 | 804 | /// For a workspace: its base afterwards, and the paths of its working |
| 791 | 805 | /// copy written or removed. |
| 792 | 806 | workspace: Option<(Option<ObjectId>, Vec<String>)>, |
| 807 | + /// What a hub that verifies the branch says of it after the landing. | |
| 808 | + hub_verify: Option<LandVerify>, | |
| 793 | 809 | } |
| 794 | 810 | |
| 795 | 811 | impl Report { |
| @@ -814,6 +830,7 @@ | ||
| 814 | 830 | conflicts: conflicts.iter().map(conflict_json).collect(), |
| 815 | 831 | next: None, |
| 816 | 832 | workspace: None, |
| 833 | + hub_verify: None, | |
| 817 | 834 | } |
| 818 | 835 | } |
| 819 | 836 | |
| @@ -838,6 +855,7 @@ | ||
| 838 | 855 | conflicts: response.conflicts.clone(), |
| 839 | 856 | next: None, |
| 840 | 857 | workspace: None, |
| 858 | + hub_verify: response.verify.clone(), | |
| 841 | 859 | } |
| 842 | 860 | } |
| 843 | 861 | |
| @@ -858,6 +876,7 @@ | ||
| 858 | 876 | conflicts: Vec::new(), |
| 859 | 877 | next: None, |
| 860 | 878 | workspace: None, |
| 879 | + hub_verify: None, | |
| 861 | 880 | }, |
| 862 | 881 | }; |
| 863 | 882 | report.workspace = Some(( |
| @@ -892,6 +911,7 @@ | ||
| 892 | 911 | report.base, |
| 893 | 912 | report.updated_paths.iter().map(|p| show(p)).collect(), |
| 894 | 913 | )), |
| 914 | + hub_verify: None, | |
| 895 | 915 | } |
| 896 | 916 | } |
| 897 | 917 | |
| @@ -914,6 +934,7 @@ | ||
| 914 | 934 | "change": hex(self.change), |
| 915 | 935 | "conflicts": self.conflicts, |
| 916 | 936 | "next": self.next, |
| 937 | + "hub_verify": self.hub_verify, | |
| 917 | 938 | }); |
| 918 | 939 | if let Some((base, updated)) = &self.workspace { |
| 919 | 940 | value["base"] = hex(*base); |
| @@ -922,6 +943,16 @@ | ||
| 922 | 943 | value |
| 923 | 944 | } |
| 924 | 945 | |
| 946 | + /// Says on standard error, in one line, that the hub holds the branch | |
| 947 | + /// red, when its answer says so. | |
| 948 | + pub(crate) fn note_red(&self) { | |
| 949 | + if let Some(verify) = &self.hub_verify | |
| 950 | + && let Some(note) = hub::verify::land_note(&self.branch, verify, None) | |
| 951 | + { | |
| 952 | + eprintln!("braid: {note}"); | |
| 953 | + } | |
| 954 | + } | |
| 955 | + | |
| 925 | 956 | pub(crate) fn exit_code(&self) -> ExitCode { |
| 926 | 957 | if self.conflicted() { |
| 927 | 958 | ExitCode::from(CONFLICTS) |
| @@ -1031,6 +1062,7 @@ | ||
| 1031 | 1062 | } else { |
| 1032 | 1063 | report.print_landing(cli); |
| 1033 | 1064 | } |
| 1065 | + report.note_red(); | |
| 1034 | 1066 | Ok(report.exit_code()) |
| 1035 | 1067 | } |
| 1036 | 1068 | |
| @@ -1241,6 +1273,7 @@ | ||
| 1241 | 1273 | crate::shell_word(&report.branch) |
| 1242 | 1274 | ))); |
| 1243 | 1275 | } |
| 1276 | + report.note_red(); | |
| 1244 | 1277 | report.json() |
| 1245 | 1278 | } |
| 1246 | 1279 | None => Value::Null, |
modified crates/cli/tests/hub.rs +24 −0
| @@ -421,6 +421,30 @@ | ||
| 421 | 421 | assert!(out.status.success(), "{}", text(&out.stderr)); |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | +/// `braid status --json` gives the hub's green and red of the branch as a | |
| 425 | +/// fetch last recorded them, and null where none was. | |
| 426 | +#[test] | |
| 427 | +fn status_gives_the_hubs_green_and_red_as_last_seen() { | |
| 428 | + let p = Place::new(); | |
| 429 | + let ws = p.workspace_with_a_commit("w1"); | |
| 430 | + let landed = json(&p.braid(&ws, &["land", "--local", "--json"], &[])); | |
| 431 | + let head = landed["head"].as_str().unwrap().to_owned(); | |
| 432 | + let status = json(&p.braid(&ws, &["status", "--json"], &[])); | |
| 433 | + assert_eq!( | |
| 434 | + (&status["hub_green"], &status["hub_red"]), | |
| 435 | + (&Value::Null, &Value::Null) | |
| 436 | + ); | |
| 437 | + for name in ["remote/hub/braid/green/main", "remote/hub/braid/red/main"] { | |
| 438 | + let out = p.braid(&p.root, &["ref", "set", name, &head], &[]); | |
| 439 | + assert!(out.status.success(), "{}", text(&out.stderr)); | |
| 440 | + } | |
| 441 | + let status = json(&p.braid(&ws, &["status", "--json"], &[])); | |
| 442 | + assert_eq!(status["hub_green"], head.as_str()); | |
| 443 | + assert_eq!(status["hub_red"], head.as_str()); | |
| 444 | + // The local green of `braid verify` is another ref. | |
| 445 | + assert_eq!(status["green"], Value::Null); | |
| 446 | +} | |
| 447 | + | |
| 424 | 448 | /// A request a stand-in hub read: its request line, its `Idempotency-Key` |
| 425 | 449 | /// and its body. |
| 426 | 450 | #[derive(Debug, Default, PartialEq, Eq)] |
modified crates/cli/tests/workspaces.rs +3 −0
| @@ -1083,6 +1083,7 @@ | ||
| 1083 | 1083 | "conflicts", |
| 1084 | 1084 | "head", |
| 1085 | 1085 | "head_before", |
| 1086 | + "hub_verify", | |
| 1086 | 1087 | "landed", |
| 1087 | 1088 | "merged_paths", |
| 1088 | 1089 | "next", |
| @@ -1126,6 +1127,8 @@ | ||
| 1126 | 1127 | let landed = json(&ws, &["land"]); |
| 1127 | 1128 | assert_eq!(keys(&landed), fields); |
| 1128 | 1129 | assert_eq!(landed["outcome"], "fast-forward"); |
| 1130 | + // No hub verifies a local landing. | |
| 1131 | + assert_eq!(landed["hub_verify"], Value::Null); | |
| 1129 | 1132 | assert_eq!(landed["head_before"], head.as_str()); |
| 1130 | 1133 | assert_eq!(landed["head"], rebased.as_str()); |
| 1131 | 1134 | assert_eq!(landed["base"], rebased.as_str()); |