community: a proposal on your board arrives as a toast, carried sealed through the inbox
This commit is contained in:
1 parent
4d03cf849b
commit
fd216ecd3d
6 files changed
+241
-1
No files matched your search
@@ -52,6 +52,17 @@ pub enum Cargo {
|
||||
Share(ShareCargo),
|
||||
SpaceInvite(SpaceInvite),
|
||||
SpaceKey(SpaceKeyCargo),
|
||||
ProposalPing(ProposalPing),
|
||||
}
|
||||
|
||||
/// "Someone put a proposal on your playlist's board." Carries only enough to
|
||||
/// name it in a toast — the board itself stays the truth, and this is a
|
||||
/// best-effort nudge: the proposal stands whether or not the ping lands.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ProposalPing {
|
||||
pub playlist_uuid: [u8; 16],
|
||||
pub name: String,
|
||||
pub proposal_id: [u8; 16],
|
||||
}
|
||||
|
||||
/// "You are on the roster now, here is where the Space is" — and, for a
|
||||
@@ -483,6 +494,7 @@ async fn dispatch(app: &tauri::AppHandle, sender: [u8; 32], cargo: Cargo) {
|
||||
Cargo::Share(s) => crate::shared_playlists::on_inbox_share(app, sender, s).await,
|
||||
Cargo::SpaceInvite(i) => crate::spaces::on_inbox_invite(app, sender, i).await,
|
||||
Cargo::SpaceKey(k) => crate::spaces::on_inbox_space_key(app, sender, k).await,
|
||||
Cargo::ProposalPing(p) => crate::proposals::on_inbox_proposal(app, sender, p),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,4 +525,44 @@ mod tests {
|
||||
assert_eq!(inbox.code_hash, "UjK4sLZqGSE2qEXwQYMvNFsTiuLSYjMJuwzVbhAtXKR");
|
||||
assert_eq!(desc.code_hash, "B4A2nMJgSKzgo72gaDJyTpFNTmjBynLFga3EiNoSVstv");
|
||||
}
|
||||
|
||||
/// The wire is the variant ORDER: bincode writes the index, so inserting a
|
||||
/// variant renumbers every one after it and silently breaks every sealed
|
||||
/// message already in flight. New cargo goes on the END, and this pins it.
|
||||
#[test]
|
||||
fn cargo_variant_indices_are_the_wire() {
|
||||
let index = |c: &Cargo| {
|
||||
let b = bincode::serialize(c).unwrap();
|
||||
u32::from_le_bytes(b[..4].try_into().unwrap())
|
||||
};
|
||||
let share = Cargo::Share(ShareCargo {
|
||||
owner: [1u8; 32],
|
||||
playlist_uuid: [2u8; 16],
|
||||
name: "n".into(),
|
||||
entry_count: 1,
|
||||
});
|
||||
let key = Cargo::SpaceKey(SpaceKeyCargo {
|
||||
space_id: [3u8; 16],
|
||||
owner: [4u8; 32],
|
||||
epoch: 9,
|
||||
key: [5u8; 32],
|
||||
});
|
||||
let ping = Cargo::ProposalPing(ProposalPing {
|
||||
playlist_uuid: [6u8; 16],
|
||||
name: "Late Night Ambient".into(),
|
||||
proposal_id: [7u8; 16],
|
||||
});
|
||||
assert_eq!(index(&share), 3, "Share moved — sealed shares in flight are now unreadable");
|
||||
assert_eq!(index(&key), 5, "SpaceKey moved — sealed keys in flight are now unreadable");
|
||||
assert_eq!(index(&ping), 6, "a new variant must be appended, never inserted");
|
||||
|
||||
let back: Cargo = bincode::deserialize(&bincode::serialize(&ping).unwrap()).unwrap();
|
||||
match back {
|
||||
Cargo::ProposalPing(p) => {
|
||||
assert_eq!(p.name, "Late Night Ambient");
|
||||
assert_eq!(p.proposal_id, [7u8; 16]);
|
||||
}
|
||||
other => panic!("round-tripped into {other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user