One helper computes every derived id, instead of seven near-copies
Several kinds of row here have an id that is a function of what they are
rather than a fresh v4 — a music artist from its tag, an agent's settings
row, a fact under a key — which is what lets two nodes create "the same"
thing without coordinating and converge on one row after sync.
Every one of them derived its id for itself, and while they all agreed on
UUIDv5, the particulars drifted: a namespace constant per site, three
conventions for joining key parts (`\u{1f}` in facts, `:` in anchors,
`\u{0}` in credentials), and no shared answer to whether the parts arrive
already normalized. Agreement on those particulars *is* the point — two
derivations that differ in any of them produce two ids just as surely as
two different algorithms would, and each side is internally consistent, so
nothing notices.
`documents::derived_id` is now the only place `Uuid::new_v5` is called for
a row id. A caller names a `Domain` and the parts of its key; the namespace
and separator are the helper's. Canonicalization moves in with it, as
`folded` (trim + case-fold) and `collapsed` (adds NFKC and a whitespace
squeeze), both idempotent so a caller that normalizes for its own reasons
can pass the result straight through. The `Domain` enum is the registry of
every derived id in the codebase; adding one has nowhere else to go.
Ids move, once. The project has no backwards-compatibility constraint and
key-derivation salts are explicitly in scope for breaking changes; the two
"have not moved" tests that pinned the old per-site formulas are replaced
by one pinning this one.
Also adds `Provenance::Syndicated` — deterministic id, listed, never
tombstoned — which the podcast agent needs next and no existing variant
said. `Anchor` has the same three predicate answers but means "an agent's
well-known singleton"; there is one syndicated document per item a
publisher released.
This commit is contained in:
1 parent
a78af76391
commit
013c885d60
13 files changed
+379
-173
No files matched your search
@@ -56,9 +56,13 @@ carrying:
|
||||
|
||||
```rust
|
||||
pub enum Provenance {
|
||||
/// The user made it or asked for it — authored, imported, or fetched from
|
||||
/// something they subscribed to. Fresh v4 id, listed, purgeable.
|
||||
/// The user made it or asked for it — authored or imported. Fresh v4 id,
|
||||
/// listed, purgeable.
|
||||
User,
|
||||
/// One item of something the user subscribed to, identified by the
|
||||
/// publisher's own id for it — a podcast episode. Deterministic id,
|
||||
/// listed, never tombstoned. (Added after this ADR; see the note below.)
|
||||
Syndicated,
|
||||
/// An agent's well-known singleton, holding user content: the root of the
|
||||
/// clippings tree. Deterministic id, listed, never tombstoned.
|
||||
Anchor,
|
||||
@@ -91,6 +95,20 @@ There is exactly one place to classify a document and exactly one place each
|
||||
consequence is derived from. A new variant is a compile error at three method
|
||||
bodies rather than a silent `false` at three unrelated call sites.
|
||||
|
||||
### `Syndicated`, added later
|
||||
|
||||
The Podcasts agent needed a document that is *visible* and has a
|
||||
*deterministic* id — every node refreshes the same feed independently, so two
|
||||
nodes reaching one episode before they sync must reach one document
|
||||
(`docs/rss-reader.md` §3.3) — and no existing variant said that. `Anchor` is
|
||||
the only one with those three predicate answers, and it means "an agent's
|
||||
well-known singleton"; there is one podcast episode per item a publisher
|
||||
released, and the ensemble may hold thousands.
|
||||
|
||||
That is the shape this ADR predicted: a new variant is one line in the enum and
|
||||
one row in `provenance_answers_all_three_questions`, and nothing else had to be
|
||||
consulted about what it means.
|
||||
|
||||
### Why `Derived` and `Machinery` are separate when nothing branches on them
|
||||
|
||||
They agree on all three predicates today, and this project's own rule is that
|
||||
|
||||
+13
-4
@@ -390,8 +390,17 @@ syncs into two rows that differ only by id and every list built on them doubles.
|
||||
sync inserts by `id`.
|
||||
|
||||
The fix is a UUIDv5 derived from the member's identifying content — `derived_edge_id`,
|
||||
`fact_id`, `list_fact_member_id`, `contact_method_id`. What matters is the constraint that
|
||||
comes with it:
|
||||
`fact_id`, `list_fact_member_id`, `contact_method_id`. All of them, and every derived
|
||||
*document* id too (music artists and albums, agent settings, anchors, podcast episodes),
|
||||
go through the one helper in `documents::derived_id`: a caller names a `Domain` and the
|
||||
parts of its key, and never sees the namespace, the separator, or `Uuid::new_v5`. That is
|
||||
not tidiness. Two derivations that agree on UUIDv5 and disagree on the separator, or on
|
||||
whether the key was case-folded first, produce two ids just as surely as two different
|
||||
algorithms would — and there is nothing to notice, because each side is internally
|
||||
consistent. Adding a derived id means adding a `Domain` variant; there is nowhere else it
|
||||
could be written.
|
||||
|
||||
What matters is the constraint that comes with it:
|
||||
|
||||
> **A derived id must be a pure function of stored bytes, and its derivation is frozen
|
||||
> forever.** Never let it consult node-local configuration or any table that ships with a
|
||||
@@ -411,8 +420,8 @@ public-suffix lists — belongs at **write** time, not at compare time. Canonica
|
||||
value as it is entered, store the canonical form, and derive the id from a trivial frozen
|
||||
rule over what was stored. Ambiguity then gets resolved once, visibly, where the user can
|
||||
correct it, instead of invisibly and differently on each node. `ContactMethod` is the
|
||||
worked example: E.164 conversion happens in the agent, and `contact_method_id` only trims
|
||||
and case-folds.
|
||||
worked example: E.164 conversion happens in the agent, and `contact_method_id` asks for
|
||||
nothing beyond the trim-and-case-fold that `derived_id`'s `folded` applies.
|
||||
|
||||
#### Latest-read child
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ Landed (steps 1–4 of "Implementation order" below):
|
||||
duration immediately, before any library exists.
|
||||
|
||||
- **Key derivation and upserts** (step 6): NFKC/casefold `normalize_key`, UUIDv5 document
|
||||
and edge ids from a fixed namespace, and the idempotent `ensure_artist`/`ensure_album`/
|
||||
and edge ids via `documents::derived_id`, and the idempotent `ensure_artist`/`ensure_album`/
|
||||
`ensure_library_edge` helpers — with the convergence test that two independent stores
|
||||
deriving from the same tags in different orders produce identical ids.
|
||||
|
||||
@@ -401,17 +401,18 @@ these need the store additions in "Required infrastructure changes".
|
||||
### Identity: deterministic UUIDs from normalized keys
|
||||
|
||||
Every derived document's `DocumentID` and every `Edge`'s `id` is a **UUIDv5** derived from a
|
||||
fixed namespace and a normalized key, rather than a fresh v4:
|
||||
normalized key, rather than a fresh v4:
|
||||
|
||||
```
|
||||
NS = a hardcoded UUID constant, "syn:music-library:v1"
|
||||
artist = uuidv5(NS, "artist\x1f" + artist_key)
|
||||
album = uuidv5(NS, "album\x1f" + artist_key + "\x1f" + album_key)
|
||||
edge = uuidv5(NS, "edge\x1f" + kind + "\x1f" + from_id + "\x1f" + to_id)
|
||||
artist = DerivedKey::new(Domain::MusicArtist).collapsed(artist_key)
|
||||
album = DerivedKey::new(Domain::MusicAlbum).collapsed(artist_key).collapsed(album_key)
|
||||
edge = DerivedKey::new(Domain::MusicEdge).part(kind).part(from_id).part(to_id)
|
||||
```
|
||||
|
||||
`DocumentID::from_uuid_bytes` already exists, so this needs no new document API — only the
|
||||
`v5` feature on the workspace `uuid` dependency.
|
||||
The namespace, the separator between key parts, and the NFKC/casefold that `collapsed`
|
||||
applies all live in `documents::derived_id`, shared with every other derived id in the
|
||||
codebase — the library does not get to have its own opinion about any of them. See
|
||||
`docs/data-model.md`'s "Derived ids, and why they must be frozen".
|
||||
|
||||
Why, in order of importance:
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
//! [`PropertyKind`] it uses, how to interpret the value — lives with that
|
||||
//! agent (e.g. `agents::notebook`'s `get_active_note`/`set_active_note`).
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::agents::AgentId;
|
||||
use crate::documents::derived_id::{DerivedKey, Domain};
|
||||
use crate::documents::{
|
||||
Document, DocumentID, DocumentType, Property, PropertyKind, PropertyValue, Provenance,
|
||||
};
|
||||
@@ -26,22 +25,9 @@ use crate::stores::document::{DocumentStore, DocumentStoreError};
|
||||
|
||||
type Result<T> = std::result::Result<T, DocumentStoreError>;
|
||||
|
||||
/// Namespace for every UUIDv5 an `AgentSettings` document id is derived from.
|
||||
///
|
||||
/// `uuid5(NAMESPACE_URL, "syn:agent-settings:v1")` — recomputable by anyone who
|
||||
/// wants to check it. Mirrors `agents::music::MUSIC_LIBRARY_NS`'s versioned-suffix
|
||||
/// escape hatch: deriving a new namespace would orphan every existing
|
||||
/// `AgentSettings` document rather than silently remapping ids, which is the
|
||||
/// right failure mode if the key scheme ever has to change incompatibly.
|
||||
const AGENT_SETTINGS_NS: Uuid = Uuid::from_bytes([
|
||||
0xc2, 0x8f, 0x57, 0xa5, 0x8d, 0xcf, 0x51, 0x82, 0x82, 0xef, 0xde, 0x71, 0x2c, 0xa6, 0x9a, 0x35,
|
||||
]);
|
||||
|
||||
/// The deterministic document id for `agent`'s settings document.
|
||||
pub fn agent_settings_document_id(agent: &AgentId) -> DocumentID {
|
||||
DocumentID::from_uuid_bytes(
|
||||
*Uuid::new_v5(&AGENT_SETTINGS_NS, agent.as_str().as_bytes()).as_bytes(),
|
||||
)
|
||||
DerivedKey::new(Domain::AgentSettings).part(agent.as_str()).document_id()
|
||||
}
|
||||
|
||||
/// Return `agent`'s settings document id, creating the document (with its
|
||||
|
||||
@@ -20,9 +20,8 @@
|
||||
//! difference is [`Provenance::Anchor`] vs [`Provenance::Machinery`] (ADR
|
||||
//! 0038); they agree only on never being purgeable.
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::agents::AgentId;
|
||||
use crate::documents::derived_id::{DerivedKey, Domain};
|
||||
use crate::documents::{
|
||||
Document, DocumentID, DocumentType, Property, PropertyKind, PropertyValue, Provenance,
|
||||
};
|
||||
@@ -31,26 +30,13 @@ use crate::stores::document::{DocumentStore, DocumentStoreError};
|
||||
|
||||
type Result<T> = std::result::Result<T, DocumentStoreError>;
|
||||
|
||||
/// Namespace for every UUIDv5 an anchor document id is derived from.
|
||||
///
|
||||
/// `uuid5(NAMESPACE_URL, "syn:anchor:v1")` — recomputable by anyone who wants
|
||||
/// to check it. Its own namespace rather than a reuse of
|
||||
/// `AGENT_SETTINGS_NS`: two documents keyed by the same agent must not collide,
|
||||
/// and the versioned suffix is the same escape hatch every other id namespace
|
||||
/// here carries — deriving a new one orphans existing anchors visibly instead
|
||||
/// of silently remapping ids.
|
||||
const ANCHOR_NS: Uuid = Uuid::from_bytes([
|
||||
0x1b, 0x0e, 0x4d, 0x5c, 0x74, 0x9a, 0x5f, 0x63, 0x9c, 0x1a, 0x2d, 0x84, 0x6f, 0xb0, 0x11, 0xe7,
|
||||
]);
|
||||
|
||||
/// The deterministic id of `agent`'s anchor named `slug`.
|
||||
///
|
||||
/// `slug` because an agent may keep more than one — a clippings root and, one
|
||||
/// day, an inbox — and because a legible key is worth having in the one place
|
||||
/// ids are hard to debug.
|
||||
pub fn anchor_document_id(agent: &AgentId, slug: &str) -> DocumentID {
|
||||
let key = format!("{}:{}", agent.as_str(), slug);
|
||||
DocumentID::from_uuid_bytes(*Uuid::new_v5(&ANCHOR_NS, key.as_bytes()).as_bytes())
|
||||
DerivedKey::new(Domain::Anchor).part(agent.as_str()).part(slug).document_id()
|
||||
}
|
||||
|
||||
/// Return the id of `agent`'s `slug` anchor, creating the document — with its
|
||||
|
||||
@@ -29,6 +29,7 @@ use crate::agents::audio_player::AudioPlayer;
|
||||
use crate::agents::streaming::{self, StreamHandle, StreamingError};
|
||||
#[cfg(feature = "multimedia")]
|
||||
use crate::content_fetch;
|
||||
use crate::documents::derived_id::{DerivedKey, Domain};
|
||||
use crate::documents::{
|
||||
Artifact, ArtifactKind, ArtifactValue, BlobHash, BlobRef, Document, DocumentAvailability,
|
||||
DocumentID, DocumentType, Edge, EdgeKind, Property, PropertyKind, PropertyValue, Provenance,
|
||||
@@ -514,22 +515,6 @@ pub fn tags_are_current(
|
||||
|
||||
// ── Library graph: keys, identity, and upserts ────────────────────────────────
|
||||
|
||||
/// Namespace for every UUIDv5 the music library derives.
|
||||
///
|
||||
/// `uuid5(NAMESPACE_URL, "syn:music-library:v1")` — recomputable by anyone who
|
||||
/// wants to check it. The `v1` suffix is the escape hatch: deriving a new
|
||||
/// namespace would orphan every existing derived document rather than silently
|
||||
/// remapping ids, which is the right failure mode if the key scheme ever has to
|
||||
/// change incompatibly.
|
||||
const MUSIC_LIBRARY_NS: Uuid = Uuid::from_bytes([
|
||||
0xc7, 0xd9, 0x7f, 0x06, 0x26, 0x63, 0x51, 0xa3, 0xbf, 0x28, 0xea, 0x93, 0xd9, 0x8d, 0xfa, 0x54,
|
||||
]);
|
||||
|
||||
/// Separator between key components. ASCII Unit Separator, which cannot occur in
|
||||
/// a normalized tag value, so `("A\x1fB", "C")` and `("A", "B\x1fC")` cannot
|
||||
/// collide.
|
||||
const KEY_SEP: char = '\x1f';
|
||||
|
||||
/// Display title for tracks with no artist tag.
|
||||
pub const UNKNOWN_ARTIST: &str = "Unknown Artist";
|
||||
/// Display title for tracks with no album tag.
|
||||
@@ -548,10 +533,7 @@ pub const UNKNOWN_ALBUM: &str = "Unknown Album";
|
||||
/// artists by retagging, but cannot split one the library has already fused.
|
||||
/// Sorting may strip articles for display; identity may not.
|
||||
pub fn normalize_key(value: &str) -> String {
|
||||
use unicode_normalization::UnicodeNormalization;
|
||||
|
||||
let folded: String = value.nfkc().collect::<String>().to_lowercase();
|
||||
folded.split_whitespace().collect::<Vec<_>>().join(" ")
|
||||
crate::documents::derived_id::collapse(value)
|
||||
}
|
||||
|
||||
/// The deterministic document id for an artist, from its normalized key.
|
||||
@@ -559,7 +541,7 @@ pub fn normalize_key(value: &str) -> String {
|
||||
/// An empty key is the "unknown artist" bucket — one shared document, not one
|
||||
/// per untagged track.
|
||||
pub fn artist_document_id(artist_key: &str) -> DocumentID {
|
||||
derived_id(&format!("artist{KEY_SEP}{artist_key}"))
|
||||
DerivedKey::new(Domain::MusicArtist).collapsed(artist_key).document_id()
|
||||
}
|
||||
|
||||
/// The deterministic document id for an album.
|
||||
@@ -567,20 +549,13 @@ pub fn artist_document_id(artist_key: &str) -> DocumentID {
|
||||
/// Scoped by artist so the fourteen distinct albums named *Greatest Hits* stay
|
||||
/// fourteen documents.
|
||||
pub fn album_document_id(artist_key: &str, album_key: &str) -> DocumentID {
|
||||
derived_id(&format!("album{KEY_SEP}{artist_key}{KEY_SEP}{album_key}"))
|
||||
DerivedKey::new(Domain::MusicAlbum).collapsed(artist_key).collapsed(album_key).document_id()
|
||||
}
|
||||
|
||||
/// The deterministic id for an edge, so two nodes deriving the same graph
|
||||
/// produce byte-identical edge rows rather than duplicates differing only by id.
|
||||
pub fn library_edge_id(kind: &EdgeKind, from_id: &DocumentID, to_id: &DocumentID) -> Uuid {
|
||||
Uuid::new_v5(
|
||||
&MUSIC_LIBRARY_NS,
|
||||
format!("edge{KEY_SEP}{}{KEY_SEP}{from_id}{KEY_SEP}{to_id}", kind.type_name()).as_bytes(),
|
||||
)
|
||||
}
|
||||
|
||||
fn derived_id(key: &str) -> DocumentID {
|
||||
DocumentID::from_uuid_bytes(*Uuid::new_v5(&MUSIC_LIBRARY_NS, key.as_bytes()).as_bytes())
|
||||
DerivedKey::new(Domain::MusicEdge).part(kind.type_name()).part(from_id).part(to_id).uuid()
|
||||
}
|
||||
|
||||
/// Create the artist document for `name` if it does not exist, and return its id.
|
||||
@@ -2279,11 +2254,10 @@ mod tests {
|
||||
// function of the key, so pin the exact values.
|
||||
assert_eq!(artist_document_id("radiohead"), artist_document_id("radiohead"));
|
||||
assert_eq!(
|
||||
artist_document_id(&normalize_key(" RADIOHEAD ")),
|
||||
artist_document_id(" RADIOHEAD "),
|
||||
artist_document_id("radiohead"),
|
||||
"normalization happens before derivation, not inside it"
|
||||
"the derivation normalizes, so a caller cannot forget to"
|
||||
);
|
||||
assert_ne!(artist_document_id("radiohead"), artist_document_id("radiohead "));
|
||||
|
||||
// An album name alone is not an identity: same album title, different
|
||||
// artists, must stay two documents.
|
||||
|
||||
@@ -28,6 +28,7 @@ use serde::{Deserialize, Serialize};
|
||||
use strum::VariantArray;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::documents::derived_id::{DerivedKey, Domain};
|
||||
use crate::documents::{
|
||||
Artifact, ArtifactKind, ArtifactValue, Document, DocumentID, DocumentType, Property,
|
||||
PropertyKind, PropertyValue, Provenance,
|
||||
@@ -36,13 +37,6 @@ use crate::node::NodePubkey;
|
||||
use crate::stores::Store;
|
||||
use crate::vault::{DEFAULT_VAULT_ID, decrypt_blob, encrypt_blob};
|
||||
|
||||
/// Namespace for [`service_credential_document_id`]. A fixed v5 namespace, as in
|
||||
/// [`anchor_document_id`](crate::agents::anchor::anchor_document_id).
|
||||
const SERVICE_CREDENTIAL_NS: Uuid = Uuid::from_u128(0x4e1b_87d2_9c34_4f60_b5a7_1d8e_2c93_0f45);
|
||||
|
||||
/// Namespace for a credential field's artifact row id.
|
||||
const SEALED_FIELD_NS: Uuid = Uuid::from_u128(0x91f6_02ac_5db8_47e1_8c02_6a4f_37b1_de29);
|
||||
|
||||
/// A service this node can hold a credential for.
|
||||
///
|
||||
/// A closed enum with no `Other` escape hatch, unlike
|
||||
@@ -140,14 +134,12 @@ type Result<T> = std::result::Result<T, CredentialError>;
|
||||
/// The one document holding `service`'s credential. Deterministic, so two nodes
|
||||
/// each given the key converge on one document instead of two.
|
||||
pub fn service_credential_document_id(service: ServiceId) -> DocumentID {
|
||||
DocumentID::from_uuid_bytes(
|
||||
*Uuid::new_v5(&SERVICE_CREDENTIAL_NS, service.as_str().as_bytes()).as_bytes(),
|
||||
)
|
||||
DerivedKey::new(Domain::ServiceCredential).part(service.as_str()).document_id()
|
||||
}
|
||||
|
||||
/// The artifact row id for one field, derived so a re-entered key overwrites.
|
||||
fn sealed_field_id(service: ServiceId, field: &str) -> Uuid {
|
||||
Uuid::new_v5(&SEALED_FIELD_NS, format!("{}\u{0}{field}", service.as_str()).as_bytes())
|
||||
DerivedKey::new(Domain::SealedField).part(service.as_str()).part(field).uuid()
|
||||
}
|
||||
|
||||
/// Whether a service's credential is absent, partly filled, or ready to use.
|
||||
|
||||
@@ -36,21 +36,20 @@
|
||||
//!
|
||||
//! So the knowledge lives at write time. [`canonical_value`] converts to E.164
|
||||
//! as the method is entered and the canonical form is what gets *stored*;
|
||||
//! [`identity_key`] is then a trivial frozen rule over stored bytes. The
|
||||
//! the id derivation's own fold ([`derived_id::fold`](super::derived_id::fold),
|
||||
//! trim and case-fold) is then a trivial frozen rule over stored bytes. The
|
||||
//! region ambiguity is resolved once, visibly, where the user can correct it.
|
||||
|
||||
use rusqlite::Transaction;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::derived_id::{DerivedKey, Domain};
|
||||
use super::{
|
||||
Artifact, ArtifactKind, ArtifactValue, ContactMethod, ContactProtocol, DocumentID, Timestamp,
|
||||
};
|
||||
use crate::node::NodePubkey;
|
||||
use crate::stores::artifact::{ArtifactStore, ArtifactStoreError};
|
||||
|
||||
/// Namespace for deterministic contact-method ids.
|
||||
const CONTACT_NS: Uuid = Uuid::from_u128(0x9d1c4a7e_3f60_4b28_8e51_a70c2d9b6f34);
|
||||
|
||||
/// Maximum length of a contact method's label ("work", "mobile").
|
||||
pub const MAX_CONTACT_LABEL_LEN: usize = 64;
|
||||
/// Maximum length of a contact method's value. Unlike a fact's value — which is
|
||||
@@ -148,18 +147,6 @@ fn canonical_handle(input: &str) -> String {
|
||||
input.trim().trim_start_matches('@').to_lowercase()
|
||||
}
|
||||
|
||||
/// The frozen rule mapping a **stored** value to the bytes its id is derived
|
||||
/// from.
|
||||
///
|
||||
/// **Do not make this cleverer.** Every input it sees has already been through
|
||||
/// [`canonical_value`], so there is nothing left for it to fix; and anything it
|
||||
/// consulted that could vary by node or by release would move the ids of rows
|
||||
/// already written. Trimming and case-folding are safe because they are
|
||||
/// stable properties of the string itself.
|
||||
fn identity_key(value: &str) -> String {
|
||||
value.trim().to_lowercase()
|
||||
}
|
||||
|
||||
/// The deterministic artifact id of one of `document_id`'s contact methods.
|
||||
///
|
||||
/// Derived from the protocol and the stored value, so two nodes recording the
|
||||
@@ -171,15 +158,11 @@ pub fn contact_method_id(
|
||||
protocol: &ContactProtocol,
|
||||
stored_value: &str,
|
||||
) -> Uuid {
|
||||
Uuid::new_v5(
|
||||
&CONTACT_NS,
|
||||
format!(
|
||||
"contact_method\u{1f}{document_id}\u{1f}{}\u{1f}{}",
|
||||
protocol.slug(),
|
||||
identity_key(stored_value)
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
DerivedKey::new(Domain::ContactMethod)
|
||||
.part(document_id)
|
||||
.part(protocol.slug())
|
||||
.folded(stored_value)
|
||||
.uuid()
|
||||
}
|
||||
|
||||
/// Add a way of reaching this person, or relabel one already recorded.
|
||||
@@ -284,7 +267,7 @@ pub fn list_contact_methods(
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
methods.sort_by_key(|m| (m.protocol.order(), identity_key(&m.value)));
|
||||
methods.sort_by_key(|m| (m.protocol.order(), super::derived_id::fold(&m.value)));
|
||||
Ok(methods)
|
||||
}
|
||||
|
||||
@@ -533,18 +516,24 @@ mod tests {
|
||||
assert!(matches!(result, Err(ContactError::UnnamedProtocol)));
|
||||
}
|
||||
|
||||
/// Guards the frozen identity rule: these ids are in peers' databases, so
|
||||
/// the derivation can never be revised. Re-derived here independently
|
||||
/// rather than by calling the function under test.
|
||||
#[test]
|
||||
fn contact_method_ids_have_not_moved() {
|
||||
const NS: Uuid = Uuid::from_u128(0x9d1c4a7e_3f60_4b28_8e51_a70c2d9b6f34);
|
||||
/// A stored value reaches the same row however it is spelled on the way
|
||||
/// in — the case- and whitespace-fold that
|
||||
/// [`DerivedKey::folded`](crate::documents::derived_id::DerivedKey::folded)
|
||||
/// applies, checked here because contact methods are where it matters:
|
||||
/// a handle retyped with different capitalization must edit one row.
|
||||
#[rstest]
|
||||
#[case(ContactProtocol::Email, "ada@example.com", " Ada@Example.COM ")]
|
||||
#[case(ContactProtocol::Mastodon, "@ada@example.social", "@Ada@Example.Social")]
|
||||
fn a_value_folds_to_one_id(
|
||||
#[case] protocol: ContactProtocol,
|
||||
#[case] one: &str,
|
||||
#[case] other: &str,
|
||||
) {
|
||||
let doc = DocumentID::from_uuid_bytes([3; 16]);
|
||||
let expected = Uuid::new_v5(
|
||||
&NS,
|
||||
format!("contact_method\u{1f}{doc}\u{1f}phone\u{1f}+15552345678").as_bytes(),
|
||||
);
|
||||
|
||||
assert_eq!(contact_method_id(&doc, &ContactProtocol::Phone, "+15552345678"), expected);
|
||||
assert_eq!(
|
||||
contact_method_id(&doc, &protocol, one),
|
||||
contact_method_id(&doc, &protocol, other)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
//! The one place a UUIDv5 identity is computed.
|
||||
//!
|
||||
//! Several kinds of row here have an id that is a function of *what they are*
|
||||
//! rather than a fresh v4: a music artist from its tag, an agent's settings
|
||||
//! row, a fact under a key, a podcast episode from its feed and the
|
||||
//! publisher's id for it. That is what lets two nodes create "the same" thing
|
||||
//! without coordinating and converge on one row after sync, instead of two
|
||||
//! that nothing can ever merge.
|
||||
//!
|
||||
//! Every one of those used to derive its id for itself, and the *particulars*
|
||||
//! drifted even though the algorithm didn't: a namespace constant per site,
|
||||
//! and three conventions for joining key parts (`\u{1f}` in facts, `:` in
|
||||
//! anchors, `\u{0}` in credentials), and no shared answer to whether the
|
||||
//! parts arrive already normalized. Agreement on those particulars is the
|
||||
//! entire point — two derivations that differ in any of them produce two ids
|
||||
//! just as surely as two different algorithms would — and nothing was
|
||||
//! enforcing it. So the derivation lives here, once. A caller supplies a
|
||||
//! [`Domain`] and the parts of its key and gets an id back; it never sees the
|
||||
//! namespace, the separator, or `Uuid::new_v5`.
|
||||
//!
|
||||
//! ```ignore
|
||||
//! DerivedKey::new(Domain::Fact).part(document_id).folded(key).uuid()
|
||||
//! ```
|
||||
//!
|
||||
//! ## Canonicalization is part of the derivation, not the caller's homework
|
||||
//!
|
||||
//! Whether `" Allergies"` and `"allergies"` are one fact is a property of the
|
||||
//! id, so the folding that decides it belongs to the thing that computes the
|
||||
//! id. [`DerivedKey::folded`] and [`DerivedKey::collapsed`] are the two forms
|
||||
//! this codebase uses; both are idempotent, so a caller that has already
|
||||
//! normalized a key for its own reasons (music groups tracks by the same
|
||||
//! form it derives ids from) can pass the normalized value through without
|
||||
//! changing the answer.
|
||||
//!
|
||||
//! ## Changing anything here moves every id
|
||||
//!
|
||||
//! The namespace, the separator, a [`Domain`]'s string, and the order and
|
||||
//! normalization of a key's parts are all inputs to the hash. Revising one
|
||||
//! silently re-points every derived row in every peer's database at an id
|
||||
//! nothing else uses. `derived_ids_have_not_moved` pins the formula so that
|
||||
//! is a test failure rather than a discovery.
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
use strum::IntoStaticStr;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::DocumentID;
|
||||
|
||||
/// The namespace every derived id in this codebase hashes under.
|
||||
///
|
||||
/// `uuid5(NAMESPACE_URL, "syn:derived-id:v1")` — recomputable by anyone who
|
||||
/// wants to check it. The `:v1` is the escape hatch: if the scheme ever has to
|
||||
/// change incompatibly, deriving a new namespace orphans every existing
|
||||
/// derived row visibly rather than silently remapping ids.
|
||||
const DERIVED_ID_NS: Uuid = Uuid::from_u128(0x85bb_b99e_984e_54e3_afec_15fe_4a22_3917);
|
||||
|
||||
/// ASCII unit separator, between the domain and each key part.
|
||||
///
|
||||
/// A separator only keeps parts apart if it cannot appear *inside* one, which
|
||||
/// is why it is a non-printing control character and why [`DerivedKey::push`]
|
||||
/// strips it from every part rather than trusting that. Without that,
|
||||
/// `("a", "b\u{1f}c")` and `("a\u{1f}b", "c")` are one key.
|
||||
const PART_SEP: char = '\u{1f}';
|
||||
|
||||
/// What kind of thing an id is being derived for — the first part of every
|
||||
/// key, so two domains can never collide however alike their remaining parts.
|
||||
///
|
||||
/// One variant per derivation in the codebase, which makes this list the
|
||||
/// registry of them: adding a derived id means adding a variant here, and
|
||||
/// there is nowhere else it could be written.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, IntoStaticStr)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum Domain {
|
||||
/// [`agents::agent_settings`](crate::agents::agent_settings) — one
|
||||
/// settings document per agent (ADR 0018). Key: the agent id.
|
||||
AgentSettings,
|
||||
/// [`agents::anchor`](crate::agents::anchor) — an agent's well-known root
|
||||
/// document. Key: the agent id and the anchor's slug.
|
||||
Anchor,
|
||||
/// [`documents::contact`](super::contact) — one way of reaching a person.
|
||||
/// Key: the document, the protocol, and the stored address.
|
||||
ContactMethod,
|
||||
/// [`documents::document::derived_edge_id`](super::derived_edge_id) — an
|
||||
/// edge an agent asserts rather than invents. Key: kind, from, to.
|
||||
Edge,
|
||||
/// [`documents::facts`](super::facts) — a single-valued fact. Key: the
|
||||
/// document and the fact's key.
|
||||
Fact,
|
||||
/// [`documents::facts`](super::facts) — one member of a multi-valued
|
||||
/// fact. Key: the document, the fact's key, and the member's value.
|
||||
ListFact,
|
||||
/// [`agents::music`](crate::agents::music) — an album document, scoped to
|
||||
/// its artist so the fourteen *Greatest Hits* stay fourteen documents.
|
||||
MusicAlbum,
|
||||
/// [`agents::music`](crate::agents::music) — an artist document. Key: the
|
||||
/// artist's normalized name; empty is the unknown-artist bucket.
|
||||
MusicArtist,
|
||||
/// [`agents::music`](crate::agents::music) — an edge of the derived
|
||||
/// library graph. Key: kind, from, to.
|
||||
MusicEdge,
|
||||
/// [`agents::podcast`](crate::agents::podcast) — an episode, scoped to
|
||||
/// its feed and keyed by the publisher's id for it.
|
||||
PodcastEpisode,
|
||||
/// [`agents::podcast_queue`](crate::agents::podcast_queue) — one entry of
|
||||
/// the cross-series play queue. Key: the settings document and the
|
||||
/// episode.
|
||||
PodcastQueueEntry,
|
||||
/// [`credentials`](crate::credentials) — one sealed field of a service's
|
||||
/// credential. Key: the service and the field name.
|
||||
SealedField,
|
||||
/// [`credentials`](crate::credentials) — the document holding one
|
||||
/// service's credential (ADR 0051). Key: the service.
|
||||
ServiceCredential,
|
||||
}
|
||||
|
||||
impl Domain {
|
||||
/// The snake_case name hashed as the key's first part.
|
||||
pub fn as_str(self) -> &'static str {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
/// A key under construction: a [`Domain`] and its parts, joined and hashed by
|
||||
/// [`uuid`](Self::uuid) or [`document_id`](Self::document_id).
|
||||
///
|
||||
/// Parts are ordered and positional — `part`/`folded`/`collapsed` differ only
|
||||
/// in how the value is canonicalized on the way in, never in where it lands —
|
||||
/// so a domain's key shape is whatever the sequence of calls says it is.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DerivedKey(String);
|
||||
|
||||
impl DerivedKey {
|
||||
/// Start a key for `domain`.
|
||||
pub fn new(domain: Domain) -> Self {
|
||||
Self(domain.as_str().to_string())
|
||||
}
|
||||
|
||||
/// Append a part verbatim — for values that are already canonical because
|
||||
/// they are this codebase's own text: an id, an enum's `as_str`, a slug.
|
||||
pub fn part(self, part: impl Display) -> Self {
|
||||
self.push(&part.to_string())
|
||||
}
|
||||
|
||||
/// Append a part [`fold`]ed: trimmed and case-folded.
|
||||
///
|
||||
/// For values a user typed, where "Allergies" and " allergies " mean the
|
||||
/// same thing and should reach the same row.
|
||||
pub fn folded(self, part: &str) -> Self {
|
||||
self.push(&fold(part))
|
||||
}
|
||||
|
||||
/// Append a part [`collapse`]d: folded, NFKC-normalized, and with runs of
|
||||
/// whitespace squeezed to one space.
|
||||
///
|
||||
/// For values a *machine elsewhere* produced, where the same name can
|
||||
/// arrive spelled several ways — file tags, feed metadata.
|
||||
pub fn collapsed(self, part: &str) -> Self {
|
||||
self.push(&collapse(part))
|
||||
}
|
||||
|
||||
/// The derived UUID, for an artifact or edge row.
|
||||
pub fn uuid(&self) -> Uuid {
|
||||
Uuid::new_v5(&DERIVED_ID_NS, self.0.as_bytes())
|
||||
}
|
||||
|
||||
/// The derived id, for a document.
|
||||
pub fn document_id(&self) -> DocumentID {
|
||||
DocumentID::from_uuid_bytes(*self.uuid().as_bytes())
|
||||
}
|
||||
|
||||
fn push(mut self, part: &str) -> Self {
|
||||
self.0.push(PART_SEP);
|
||||
self.0.extend(part.chars().filter(|c| *c != PART_SEP));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Trim and case-fold — the identity of a value a user typed.
|
||||
///
|
||||
/// `to_lowercase` rather than an ASCII fold so the same intuition holds for
|
||||
/// non-ASCII keys.
|
||||
pub fn fold(value: &str) -> String {
|
||||
value.trim().to_lowercase()
|
||||
}
|
||||
|
||||
/// [`fold`], plus NFKC composition and collapsing every run of whitespace to a
|
||||
/// single space — the identity of a value some other program produced.
|
||||
///
|
||||
/// NFKC so `"Beyoncé"` and `"Beyonce\u{301}"` are one name; the whitespace
|
||||
/// collapse so a tagger's double space is not a second artist. Deliberately
|
||||
/// *not* cleverer than that: stripping a leading "The", or punctuation, would
|
||||
/// merge names that are genuinely different ("Wham!" and "Wham").
|
||||
pub fn collapse(value: &str) -> String {
|
||||
use unicode_normalization::UnicodeNormalization;
|
||||
|
||||
let folded: String = value.nfkc().collect::<String>().to_lowercase();
|
||||
folded.split_whitespace().collect::<Vec<_>>().join(" ")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rstest::rstest;
|
||||
|
||||
/// The frozen formula, re-derived here independently rather than by
|
||||
/// calling the code under test. Every derived row in every peer's database
|
||||
/// was hashed this way; a change that moves them should fail here first.
|
||||
#[test]
|
||||
fn derived_ids_have_not_moved() {
|
||||
const NS: Uuid = Uuid::from_u128(0x85bb_b99e_984e_54e3_afec_15fe_4a22_3917);
|
||||
let expected = Uuid::new_v5(&NS, "fact\u{1f}doc-7\u{1f}allergies".as_bytes());
|
||||
|
||||
assert_eq!(
|
||||
DerivedKey::new(Domain::Fact).part("doc-7").folded(" Allergies ").uuid(),
|
||||
expected
|
||||
);
|
||||
}
|
||||
|
||||
/// Two domains sharing a key shape must not share ids — the reason the
|
||||
/// domain is hashed rather than merely documented.
|
||||
#[test]
|
||||
fn domains_do_not_collide() {
|
||||
let fact = DerivedKey::new(Domain::Fact).part("a").part("b").uuid();
|
||||
let list = DerivedKey::new(Domain::ListFact).part("a").part("b").uuid();
|
||||
|
||||
assert_ne!(fact, list);
|
||||
}
|
||||
|
||||
/// Parts are separated, not concatenated: no regrouping of the same
|
||||
/// characters reaches the same id.
|
||||
#[test]
|
||||
fn part_boundaries_are_significant() {
|
||||
let split = DerivedKey::new(Domain::Edge).part("a").part("bc").uuid();
|
||||
let other = DerivedKey::new(Domain::Edge).part("ab").part("c").uuid();
|
||||
|
||||
assert_ne!(split, other);
|
||||
}
|
||||
|
||||
/// A part carrying the separator cannot forge a boundary — the reason
|
||||
/// `push` strips it rather than trusting that no key contains it.
|
||||
#[test]
|
||||
fn a_part_cannot_smuggle_in_a_separator() {
|
||||
let smuggled = DerivedKey::new(Domain::Edge).part("a\u{1f}b").part("c").uuid();
|
||||
let genuine = DerivedKey::new(Domain::Edge).part("a").part("b").part("c").uuid();
|
||||
|
||||
assert_ne!(smuggled, genuine);
|
||||
}
|
||||
|
||||
/// Canonicalizing twice is canonicalizing once, which is what lets a
|
||||
/// caller that normalizes for its own reasons pass the result through.
|
||||
#[rstest]
|
||||
#[case(" RADIOHEAD ")]
|
||||
#[case("Sigur\tRós\n")]
|
||||
#[case("Godspeed You! Black Emperor")]
|
||||
fn canonicalization_is_idempotent(#[case] raw: &str) {
|
||||
assert_eq!(fold(&fold(raw)), fold(raw));
|
||||
assert_eq!(collapse(&collapse(raw)), collapse(raw));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use uuid::Uuid;
|
||||
use crate::node::NodePubkey;
|
||||
|
||||
use super::Timestamp;
|
||||
use super::derived_id::{DerivedKey, Domain};
|
||||
pub use crate::vault::VaultId;
|
||||
|
||||
/// Unique identifier for a [`Document`], backed by a UUID v4.
|
||||
@@ -270,11 +271,26 @@ impl DocumentType {
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum Provenance {
|
||||
/// The user made it or asked for it — authored, imported, or fetched from
|
||||
/// something they subscribed to. A fresh v4 id, listed, purgeable. Almost
|
||||
/// everything.
|
||||
/// The user made it or asked for it — authored or imported. A fresh v4
|
||||
/// id, listed, purgeable. Almost everything.
|
||||
#[default]
|
||||
User,
|
||||
/// One item of something the user subscribed to, identified by the
|
||||
/// publisher's own id for it — a podcast episode, and one day an RSS
|
||||
/// article. Deterministic id, listed, never tombstoned.
|
||||
///
|
||||
/// Distinct from [`Anchor`](Self::Anchor) by not being a singleton: there
|
||||
/// is one of these per item a source published, and the ensemble may hold
|
||||
/// thousands. Distinct from [`Derived`](Self::Derived) by being *visible*
|
||||
/// and by not being recomputable from anything this store holds — the
|
||||
/// source is a server somewhere, which may have dropped the item.
|
||||
///
|
||||
/// The id is deterministic because every node refreshes the same feed
|
||||
/// independently, with no leader election: two nodes that fetch before
|
||||
/// they sync must reach one document, or the ensemble holds two of every
|
||||
/// episode forever, with independent listen state. `docs/rss-reader.md`
|
||||
/// §3.3 is the long form.
|
||||
Syndicated,
|
||||
/// An agent's well-known singleton, holding user content — the root of the
|
||||
/// clippings tree (ADR 0039). Deterministic id, listed, never tombstoned.
|
||||
///
|
||||
@@ -560,10 +576,6 @@ impl EdgeKind {
|
||||
}
|
||||
}
|
||||
|
||||
/// Namespace for [`derived_edge_id`]. A fixed v5 namespace, as in the music
|
||||
/// library's [`library_edge_id`](crate::agents::music::library_edge_id).
|
||||
const DERIVED_EDGE_NS: Uuid = Uuid::from_u128(0x7f3a1c94_5b2e_4d18_9a06_c3e5f70b2841);
|
||||
|
||||
/// The deterministic id of the `kind` edge from `from_id` to `to_id`.
|
||||
///
|
||||
/// For edges an agent asserts rather than invents: two nodes that
|
||||
@@ -576,10 +588,7 @@ const DERIVED_EDGE_NS: Uuid = Uuid::from_u128(0x7f3a1c94_5b2e_4d18_9a06_c3e5f70b
|
||||
/// Use [`Edge::new`]'s fresh v4 only for edges whose duplication is
|
||||
/// meaningful, i.e. where the same triple can legitimately exist twice.
|
||||
pub fn derived_edge_id(kind: &EdgeKind, from_id: &DocumentID, to_id: &DocumentID) -> Uuid {
|
||||
Uuid::new_v5(
|
||||
&DERIVED_EDGE_NS,
|
||||
format!("{}\u{1f}{from_id}\u{1f}{to_id}", kind.type_name()).as_bytes(),
|
||||
)
|
||||
DerivedKey::new(Domain::Edge).part(kind.type_name()).part(from_id).part(to_id).uuid()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -592,6 +601,7 @@ mod tests {
|
||||
/// build rather than inheriting somebody else's answers.
|
||||
#[rstest]
|
||||
#[case(Provenance::User, false, true, false)]
|
||||
#[case(Provenance::Syndicated, false, false, true)]
|
||||
#[case(Provenance::Anchor, false, false, true)]
|
||||
#[case(Provenance::Derived, true, false, true)]
|
||||
#[case(Provenance::Machinery, true, false, true)]
|
||||
|
||||
@@ -46,18 +46,11 @@
|
||||
use rusqlite::Transaction;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::derived_id::{DerivedKey, Domain};
|
||||
use super::{Artifact, ArtifactKind, ArtifactValue, DocumentID, Fact, Timestamp};
|
||||
use crate::node::NodePubkey;
|
||||
use crate::stores::artifact::{ArtifactStore, ArtifactStoreError};
|
||||
|
||||
/// Namespace for deterministic fact ids.
|
||||
const FACT_NS: Uuid = Uuid::from_u128(0x2b4e07d1_8c63_4f52_b90a_6de41f8ac357);
|
||||
|
||||
/// Namespace for deterministic list-fact member ids. Distinct from [`FACT_NS`]
|
||||
/// so a single-valued and a multi-valued fact under the same key cannot collide
|
||||
/// on one row.
|
||||
const LIST_FACT_NS: Uuid = Uuid::from_u128(0x5c81ba36_4f07_49d3_a2ee_1b90d7c46f28);
|
||||
|
||||
/// Maximum length, in characters, of a fact's key. The value is deliberately
|
||||
/// uncapped — it is free-form content, like a note body — but the key is an
|
||||
/// identifier the UI has to lay out in a label column.
|
||||
@@ -88,12 +81,14 @@ type Result<T> = std::result::Result<T, FactError>;
|
||||
///
|
||||
/// So "Allergies", "allergies" and " Allergies " are one fact, which is what a
|
||||
/// user typing into a free-text field expects. The *stored* key keeps the
|
||||
/// spelling as typed; only the id derivation sees this form.
|
||||
/// spelling as typed; only the id derivation and the groupings below see this
|
||||
/// form.
|
||||
///
|
||||
/// ASCII-insensitive folding would be enough for the id to be stable, but
|
||||
/// `to_lowercase` is used so the same intuition holds for non-ASCII keys.
|
||||
/// The derivation itself no longer calls this — [`DerivedKey::folded`] applies
|
||||
/// the same fold — but grouping and comparing facts by key needs the form as a
|
||||
/// value, and it must be the *same* form the ids were derived from.
|
||||
fn normalize_key(key: &str) -> String {
|
||||
key.trim().to_lowercase()
|
||||
super::derived_id::fold(key)
|
||||
}
|
||||
|
||||
/// The deterministic artifact id of `document_id`'s fact under `key`.
|
||||
@@ -102,10 +97,7 @@ fn normalize_key(key: &str) -> String {
|
||||
/// row that reconciles by timestamp, instead of two rows that never do. See the
|
||||
/// module docs.
|
||||
pub fn fact_id(document_id: &DocumentID, key: &str) -> Uuid {
|
||||
Uuid::new_v5(
|
||||
&FACT_NS,
|
||||
format!("fact\u{1f}{document_id}\u{1f}{}", normalize_key(key)).as_bytes(),
|
||||
)
|
||||
DerivedKey::new(Domain::Fact).part(document_id).folded(key).uuid()
|
||||
}
|
||||
|
||||
fn check_key(key: &str) -> Result<()> {
|
||||
@@ -233,15 +225,7 @@ pub fn remove_fact(
|
||||
/// Both key and value are normalized, so adding "Seymour" where "seymour" is
|
||||
/// already listed updates that member's spelling rather than duplicating it.
|
||||
pub fn list_fact_member_id(document_id: &DocumentID, key: &str, value: &str) -> Uuid {
|
||||
Uuid::new_v5(
|
||||
&LIST_FACT_NS,
|
||||
format!(
|
||||
"list_fact\u{1f}{document_id}\u{1f}{}\u{1f}{}",
|
||||
normalize_key(key),
|
||||
normalize_key(value)
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
DerivedKey::new(Domain::ListFact).part(document_id).folded(key).folded(value).uuid()
|
||||
}
|
||||
|
||||
/// Add `value` to `document_id`'s list fact under `key`, returning the member's
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
mod artifact;
|
||||
mod availability;
|
||||
pub mod contact;
|
||||
pub mod derived_id;
|
||||
mod document;
|
||||
pub mod facts;
|
||||
pub mod import;
|
||||
|
||||
@@ -216,19 +216,15 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wikilink_edge_ids_have_not_moved() {
|
||||
// `wikilink_edge_id` used to hash its own namespace and its own
|
||||
// literal "wiki_link" tag; it now defers to `derived_edge_id`. Every
|
||||
// wikilink edge already synced to a peer carries the old id, so the
|
||||
// two derivations have to agree forever, not just today — this
|
||||
// re-derives the original formula independently rather than asserting
|
||||
// one call equals another.
|
||||
const OLD_NS: Uuid = Uuid::from_u128(0x7f3a1c94_5b2e_4d18_9a06_c3e5f70b2841);
|
||||
fn a_wikilink_edge_id_is_the_shared_edge_derivation() {
|
||||
// `wikilink_edge_id` once hashed its own namespace and its own literal
|
||||
// "wiki_link" tag. It is a thin alias now, and the point of the alias
|
||||
// is that it stays one: a private formula here would put wikilink
|
||||
// edges at ids nothing else in the codebase can reach.
|
||||
let from = DocumentID::from_uuid_bytes([7; 16]);
|
||||
let to = DocumentID::from_uuid_bytes([9; 16]);
|
||||
|
||||
let old = Uuid::new_v5(&OLD_NS, format!("wiki_link\u{1f}{from}\u{1f}{to}").as_bytes());
|
||||
assert_eq!(wikilink_edge_id(&from, &to), old);
|
||||
assert_eq!(wikilink_edge_id(&from, &to), derived_edge_id(&EdgeKind::WikiLink, &from, &to));
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
|
||||
Reference in new issue
Block a user