aboutsummaryrefslogtreecommitdiffstats
path: root/src/document/mod.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 13:30:31 +0100
committertv <tv@krebsco.de>2026-10-31 13:30:31 +0100
commitb1464bdf5f4259087d2f2864f3f3d63ccfb9e6f9 (patch)
treebe2f085552fd41eabb58068a4e98c6a87a05d0ff /src/document/mod.rs
parent84582abb56653d1f58d9e838b242f48d8a4ea557 (diff)
add guard test for automerge imports
Diffstat (limited to 'src/document/mod.rs')
-rw-r--r--src/document/mod.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/document/mod.rs b/src/document/mod.rs
index d7d3e88..1612145 100644
--- a/src/document/mod.rs
+++ b/src/document/mod.rs
@@ -12,3 +12,57 @@ pub(crate) mod lock;
pub(crate) mod meta;
pub(crate) mod replica;
pub(crate) mod store;
+
+#[cfg(test)]
+mod tests {
+ use std::path::{Path, PathBuf};
+
+ /// Every `.rs` file under `dir`.
+ fn sources(dir: &Path, out: &mut Vec<PathBuf>) {
+ for entry in std::fs::read_dir(dir).unwrap() {
+ let path = entry.unwrap().path();
+ if path.is_dir() {
+ sources(&path, out);
+ } else if path.extension().is_some_and(|extension| extension == "rs") {
+ out.push(path);
+ }
+ }
+ }
+
+ /// Automerge is used only in `document`, `remake` and the sync session
+ /// (`state/session.rs`); the rest of the node names its types as `document`
+ /// re-exports them and works through `document` (`architecture.md`, The document).
+ #[test]
+ fn automerge_stays_behind_document() {
+ let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
+ let allowed = [
+ src.join("document"),
+ src.join("remake"),
+ src.join("state").join("session.rs"),
+ ];
+ let mut files = Vec::new();
+ sources(&src, &mut files);
+ let mut found = Vec::new();
+ for file in files
+ .iter()
+ .filter(|file| !allowed.iter().any(|allowed| file.starts_with(allowed)))
+ {
+ let text = std::fs::read_to_string(file).unwrap();
+ for (number, line) in text.lines().enumerate() {
+ if line.contains("automerge::") || line.trim_start().starts_with("use automerge") {
+ found.push(format!(
+ "{}:{}: {}",
+ file.display(),
+ number + 1,
+ line.trim()
+ ));
+ }
+ }
+ }
+ assert!(
+ found.is_empty(),
+ "Automerge used outside `document`:\n{}",
+ found.join("\n")
+ );
+ }
+}