mirror of
https://github.com/ModernRelay/omnigraph.git
synced 2026-06-24 02:38:06 +02:00
The inline `mod tests` in crates/omnigraph/src/db/omnigraph.rs had grown to ~620 lines, mixing tests that need crate-private access with tests that only exercise the public API. Splits the latter out. - tests/lifecycle.rs: 10 init/open/snapshot/drift tests - tests/schema_apply.rs: 5 plan/apply tests - omnigraph.rs: 10 tests remain inline because they use db.coordinator, db.table_store(), ManifestCoordinator, SCHEMA_APPLY_LOCK_BRANCH, or is_internal_run_branch — all crate-private and intentionally kept so. No behavior change. Zero semantic edits to the tests themselves beyond replacing db.snapshot() (pub(crate)) with snapshot_main helper at integration-test boundaries. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
101 lines
3.1 KiB
Rust
101 lines
3.1 KiB
Rust
mod helpers;
|
|
|
|
use std::fs;
|
|
|
|
use omnigraph::db::{Omnigraph, ReadTarget};
|
|
use omnigraph_compiler::{SchemaMigrationStep, SchemaTypeKind};
|
|
|
|
use helpers::*;
|
|
|
|
#[tokio::test]
|
|
async fn plan_schema_reports_supported_additive_change() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let uri = dir.path().to_str().unwrap();
|
|
let db = Omnigraph::init(uri, TEST_SCHEMA).await.unwrap();
|
|
|
|
let desired = TEST_SCHEMA.replace(
|
|
" age: I32?\n}",
|
|
" age: I32?\n nickname: String?\n}",
|
|
);
|
|
|
|
let plan = db.plan_schema(&desired).await.unwrap();
|
|
assert!(plan.supported);
|
|
assert!(plan.steps.iter().any(|step| matches!(
|
|
step,
|
|
SchemaMigrationStep::AddProperty {
|
|
type_kind: SchemaTypeKind::Node,
|
|
type_name,
|
|
property_name,
|
|
..
|
|
} if type_name == "Person" && property_name == "nickname"
|
|
)));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn plan_schema_rejects_when_schema_contract_has_drifted() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let uri = dir.path().to_str().unwrap();
|
|
let db = Omnigraph::init(uri, TEST_SCHEMA).await.unwrap();
|
|
|
|
let drifted = TEST_SCHEMA.replace("age: I32?", "age: I64?");
|
|
fs::write(dir.path().join("_schema.pg"), drifted).unwrap();
|
|
|
|
let err = db.plan_schema(TEST_SCHEMA).await.unwrap_err();
|
|
assert!(
|
|
err.to_string()
|
|
.contains("current _schema.pg no longer matches the accepted compiled schema")
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn apply_schema_noop_returns_not_applied() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let uri = dir.path().to_str().unwrap();
|
|
let mut db = Omnigraph::init(uri, TEST_SCHEMA).await.unwrap();
|
|
|
|
let result = db.apply_schema(TEST_SCHEMA).await.unwrap();
|
|
assert!(result.supported);
|
|
assert!(!result.applied);
|
|
assert!(result.steps.is_empty());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn apply_schema_rejects_when_non_main_branch_exists() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let uri = dir.path().to_str().unwrap();
|
|
let mut db = Omnigraph::init(uri, TEST_SCHEMA).await.unwrap();
|
|
db.branch_create("feature").await.unwrap();
|
|
|
|
let desired = TEST_SCHEMA.replace(
|
|
" age: I32?\n}",
|
|
" age: I32?\n nickname: String?\n}",
|
|
);
|
|
let err = db.apply_schema(&desired).await.unwrap_err();
|
|
assert!(
|
|
err.to_string()
|
|
.contains("schema apply requires a repo with only main")
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn apply_schema_unsupported_plan_does_not_advance_manifest() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let uri = dir.path().to_str().unwrap();
|
|
let mut db = Omnigraph::init(uri, TEST_SCHEMA).await.unwrap();
|
|
let before_version = db
|
|
.snapshot_of(ReadTarget::branch("main"))
|
|
.await
|
|
.unwrap()
|
|
.version();
|
|
|
|
let desired = TEST_SCHEMA.replace("age: I32?", "age: I64?");
|
|
let err = db.apply_schema(&desired).await.unwrap_err();
|
|
assert!(err.to_string().contains("changing property type"));
|
|
assert_eq!(
|
|
db.snapshot_of(ReadTarget::branch("main"))
|
|
.await
|
|
.unwrap()
|
|
.version(),
|
|
before_version
|
|
);
|
|
}
|