git-ents.gitmain
⌘K
foforge
account.rs64 lines · 2.1 KB · rusthistorycomment on this file
1//! The Account entity: links a member's key to a login identity.
2//!
3//! Spec coverage: `model.account`.
4
5use facet::Facet;
6
7use crate::member::MemberId;
8
9/// Links a member to a login identity, living at the fixed
10/// `refs/meta/account` ref (`namespace::ACCOUNT_REF`,
11/// `meta-ref.granularity`: repository-global state with a single
12/// writer-of-record lives on one fixed ref, not one ref per entity).
13///
14/// `model.account` requires authentication state to live in the
15/// repository as ordinary forge state, never a session database or token
16/// table — this struct is that state, nothing more: which member the
17/// account belongs to, and the login identity it maps to. What that login
18/// identity looks like (an email, an OAuth subject, a passkey credential
19/// id) is left to whatever frontend authenticates against it; `ents-model`
20/// does not constrain its format.
21///
22/// # Examples
23///
24/// ```
25/// use ents_model::{Account, MemberId};
26///
27/// let account = Account {
28/// member: MemberId::new("jdc"),
29/// login: "joseph.carpinelli@icloud.com".to_owned(),
30/// };
31/// let (id, store) = facet_git_tree::serialize(&account).expect("serialize");
32/// let back: Account = facet_git_tree::deserialize(&id, &store).expect("deserialize");
33/// assert_eq!(back, account);
34/// ```
35// @relation(model.account, meta-ref.typed-tree, model.extensibility, scope=file)
36#[derive(Debug, Clone, PartialEq, Eq, Facet)]
37pub struct Account {
38 /// The member this account belongs to.
39 pub member: MemberId,
40 /// The login identity the member authenticates as.
41 pub login: String,
42}
43
44#[cfg(test)]
45mod tests {
46 #![allow(clippy::expect_used, reason = "unit test")]
47
48 use facet_git_tree::{deserialize, serialize};
49 use rstest::rstest;
50
51 use super::*;
52
53 #[rstest]
54 // @relation(model.account, meta-ref.typed-tree, scope=function, role=Verifies)
55 fn account_round_trips_through_a_tree() {
56 let account = Account {
57 member: MemberId::new("jdc"),
58 login: "joseph.carpinelli@icloud.com".to_owned(),
59 };
60 let (id, store) = serialize(&account).expect("serialize");
61 let back: Account = deserialize(&id, &store).expect("deserialize");
62 assert_eq!(back, account);
63 }
64}