pub(crate) const EVENT: &str = "evt";
pub(crate) const REVISION: &str = "rev";
pub(crate) const OBJECT: &str = "obj";
pub(crate) const ENGAGEMENT: &str = "engagement";
pub(crate) const OBSERVATION: &str = "obs";
pub(crate) const ASSESSMENT: &str = "assess";
pub(crate) const VALIDATION: &str = "validation";
pub(crate) const INPUT_REQUEST: &str = "input-request";
pub(crate) const INPUT_REQUEST_RESPONSE: &str = "input-request-response";
pub(crate) const COMMIT_ASSOCIATION: &str = "assoc-commit";
pub(crate) const REF_ASSOCIATION: &str = "assoc-ref";
pub(crate) const COMMIT_WITHDRAWAL: &str = "withdraw-commit";
pub(crate) const REF_WITHDRAWAL: &str = "withdraw-ref";
pub(crate) const TASK_ATTEMPT: &str = "task-attempt";
pub(crate) const CHECKPOINT: &str = "checkpoint";
pub(crate) const SUBJECT: &str = "subject";
pub(crate) const JOURNAL: &str = "journal";
pub(crate) const REVIEW: &str = "review";
pub(crate) const ACTOR: &str = "actor";
pub(crate) const ROW: &str = "row";
pub(crate) const ARTIFACT_OBJECT: &str = "object";
pub(crate) const ARTIFACT_BODY: &str = "body";
pub(crate) const NOTE_BODY: &str = "note-body";
pub(crate) const REDACTED_FILE: &str = "file";
pub(crate) const UNIX_MS: &str = "unix-ms";
#[cfg(test)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum PrefixKind {
ContentId,
StructuralId,
ArtifactRef,
Token,
}
#[cfg(test)]
pub(crate) struct IdPrefix {
pub(crate) prefix: &'static str,
pub(crate) kind: PrefixKind,
pub(crate) minted: bool,
pub(crate) linkified: bool,
}
#[cfg(test)]
pub(crate) const ID_PREFIXES: &[IdPrefix] = &[
IdPrefix {
prefix: EVENT,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: REVISION,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: OBJECT,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: ENGAGEMENT,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: OBSERVATION,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: ASSESSMENT,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: VALIDATION,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: INPUT_REQUEST,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: INPUT_REQUEST_RESPONSE,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: COMMIT_ASSOCIATION,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: REF_ASSOCIATION,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: COMMIT_WITHDRAWAL,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: REF_WITHDRAWAL,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: TASK_ATTEMPT,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: CHECKPOINT,
kind: PrefixKind::ContentId,
minted: true,
linkified: true,
},
IdPrefix {
prefix: SUBJECT,
kind: PrefixKind::ContentId,
minted: true,
linkified: false,
},
IdPrefix {
prefix: JOURNAL,
kind: PrefixKind::StructuralId,
minted: true,
linkified: false,
},
IdPrefix {
prefix: REVIEW,
kind: PrefixKind::StructuralId,
minted: true,
linkified: false,
},
IdPrefix {
prefix: ACTOR,
kind: PrefixKind::StructuralId,
minted: true,
linkified: false,
},
IdPrefix {
prefix: ROW,
kind: PrefixKind::StructuralId,
minted: true,
linkified: false,
},
IdPrefix {
prefix: ARTIFACT_OBJECT,
kind: PrefixKind::ArtifactRef,
minted: true,
linkified: false,
},
IdPrefix {
prefix: ARTIFACT_BODY,
kind: PrefixKind::ArtifactRef,
minted: true,
linkified: false,
},
IdPrefix {
prefix: NOTE_BODY,
kind: PrefixKind::ArtifactRef,
minted: true,
linkified: false,
},
IdPrefix {
prefix: REDACTED_FILE,
kind: PrefixKind::ArtifactRef,
minted: true,
linkified: false,
},
IdPrefix {
prefix: UNIX_MS,
kind: PrefixKind::Token,
minted: true,
linkified: false,
},
];
#[cfg(test)]
mod tests {
use std::collections::HashSet;
use super::*;
#[test]
fn prefix_constants_are_frozen() {
assert_eq!(EVENT, "evt");
assert_eq!(REVISION, "rev");
assert_eq!(OBJECT, "obj");
assert_eq!(ENGAGEMENT, "engagement");
assert_eq!(OBSERVATION, "obs");
assert_eq!(ASSESSMENT, "assess");
assert_eq!(VALIDATION, "validation");
assert_eq!(INPUT_REQUEST, "input-request");
assert_eq!(INPUT_REQUEST_RESPONSE, "input-request-response");
assert_eq!(COMMIT_ASSOCIATION, "assoc-commit");
assert_eq!(REF_ASSOCIATION, "assoc-ref");
assert_eq!(COMMIT_WITHDRAWAL, "withdraw-commit");
assert_eq!(REF_WITHDRAWAL, "withdraw-ref");
assert_eq!(TASK_ATTEMPT, "task-attempt");
assert_eq!(CHECKPOINT, "checkpoint");
assert_eq!(JOURNAL, "journal");
assert_eq!(REVIEW, "review");
assert_eq!(ACTOR, "actor");
assert_eq!(ROW, "row");
assert_eq!(ARTIFACT_OBJECT, "object");
assert_eq!(ARTIFACT_BODY, "body");
assert_eq!(NOTE_BODY, "note-body");
assert_eq!(REDACTED_FILE, "file");
assert_eq!(UNIX_MS, "unix-ms");
}
#[test]
fn registry_prefixes_are_unique() {
let mut seen = HashSet::new();
for entry in ID_PREFIXES {
assert!(
seen.insert(entry.prefix),
"duplicate registry prefix: {}",
entry.prefix
);
}
}
#[test]
fn registry_prefixes_use_the_reserved_charset() {
for entry in ID_PREFIXES {
let mut chars = entry.prefix.chars();
let first = chars.next().expect("prefix must be non-empty");
assert!(
first.is_ascii_lowercase(),
"{} must open lowercase",
entry.prefix
);
assert!(
chars.all(|c| c.is_ascii_lowercase() || c == '-'),
"{} must be lowercase letters and hyphens",
entry.prefix
);
assert!(
!entry.prefix.ends_with('-'),
"{} must not end with a hyphen",
entry.prefix
);
}
}
#[test]
fn every_minted_constant_is_registered_exactly_once() {
let minted = [
EVENT,
REVISION,
OBJECT,
ENGAGEMENT,
OBSERVATION,
ASSESSMENT,
VALIDATION,
INPUT_REQUEST,
INPUT_REQUEST_RESPONSE,
COMMIT_ASSOCIATION,
REF_ASSOCIATION,
COMMIT_WITHDRAWAL,
REF_WITHDRAWAL,
TASK_ATTEMPT,
CHECKPOINT,
SUBJECT,
JOURNAL,
REVIEW,
ACTOR,
ROW,
ARTIFACT_OBJECT,
ARTIFACT_BODY,
NOTE_BODY,
REDACTED_FILE,
UNIX_MS,
];
assert_eq!(ID_PREFIXES.len(), minted.len());
for prefix in minted {
let entry = ID_PREFIXES
.iter()
.find(|e| e.prefix == prefix)
.unwrap_or_else(|| panic!("{prefix} missing from the table"));
assert!(entry.minted, "{prefix} is a production-minted prefix");
assert_eq!(
ID_PREFIXES.iter().filter(|e| e.prefix == prefix).count(),
1,
"{prefix} must appear in the table exactly once"
);
}
}
#[test]
fn registry_kind_partition_is_stable() {
let count = |kind: PrefixKind| ID_PREFIXES.iter().filter(|e| e.kind == kind).count();
assert_eq!(count(PrefixKind::ContentId), 16);
assert_eq!(count(PrefixKind::StructuralId), 4);
assert_eq!(count(PrefixKind::ArtifactRef), 4);
assert_eq!(count(PrefixKind::Token), 1);
}
#[test]
fn inspector_ref_prefixes_match_the_registry() {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("src/cli/inspect/web/src/classNames.ts");
if !path.exists() {
eprintln!("skipping inspector drift check: web sources not present");
return;
}
let source = std::fs::read_to_string(&path).expect("read classNames.ts");
let mut web = parse_ref_id_prefixes(&source);
let mut registry: Vec<&str> = ID_PREFIXES
.iter()
.filter(|entry| entry.linkified)
.map(|entry| entry.prefix)
.collect();
web.sort_unstable();
registry.sort_unstable();
assert_eq!(
web, registry,
"REF_ID_PREFIXES (classNames.ts) and the registry's linkified entries drifted; \
change both together"
);
}
#[test]
fn linkified_entries_are_content_ids() {
for entry in ID_PREFIXES {
if entry.linkified {
assert_eq!(
entry.kind,
PrefixKind::ContentId,
"{}: only content ids are linkifiable",
entry.prefix
);
}
if !entry.minted {
assert!(
entry.linkified,
"{}: a legacy entry that is neither minted nor linkified is dead weight",
entry.prefix
);
}
}
}
fn parse_ref_id_prefixes(source: &str) -> Vec<&str> {
let start = source
.find("REF_ID_PREFIXES = [")
.expect("classNames.ts must declare REF_ID_PREFIXES");
let block = &source[start..];
let end = block.find(']').expect("REF_ID_PREFIXES block must close");
let block = &block[..end];
let prefixes: Vec<&str> = block.split('"').skip(1).step_by(2).collect();
assert!(
!prefixes.is_empty(),
"REF_ID_PREFIXES parsed empty — the parser or the list is broken"
);
prefixes
}
#[test]
fn no_legacy_unminted_entries_remain() {
let legacy: Vec<&str> = ID_PREFIXES
.iter()
.filter(|e| !e.minted)
.map(|e| e.prefix)
.collect();
assert!(
legacy.is_empty(),
"no unminted legacy display entries should remain: {legacy:?}"
);
}
#[test]
fn promoted_content_ids_are_linkified() {
for prefix in [
OBJECT,
ENGAGEMENT,
CHECKPOINT,
TASK_ATTEMPT,
COMMIT_ASSOCIATION,
REF_ASSOCIATION,
COMMIT_WITHDRAWAL,
REF_WITHDRAWAL,
] {
let entry = ID_PREFIXES
.iter()
.find(|e| e.prefix == prefix)
.unwrap_or_else(|| panic!("{prefix} missing from the table"));
assert!(entry.linkified, "{prefix} should be linkified after #344");
}
}
}