mirror of
https://github.com/ModernRelay/omnigraph.git
synced 2026-06-27 02:39:38 +02:00
mr-668: close coverage gaps surfaced by the test-coverage audit
The bot-review pass and the subsequent coverage audit surfaced two material gaps in PR #119's test surface — both easy to close, both worth closing before merge. * **Gap 1 — cluster-route sweep.** The Bug-1 path-extractor regression slipped through because `cluster_routes_dispatch_per_graph_handle` only exercised `/snapshot`. The other six protected cluster routes (`/read`, `/change`, `/export`, `/schema`, `/schema/apply`, `/ingest`, `/branches/merge`) were implicitly trusted to work without any multi-mode integration test. Add `all_protected_cluster_routes_resolve_to_their_handler` (`tests/server.rs`) that hits each protected cluster route with a minimal request and asserts the response is consistent with the handler being reached — no 404 (router didn't match), no 500 with "Wrong number of path arguments" (Bug-1 class), no 500 with "missing extension" (routing middleware didn't inject the handle). Status code is a negative assertion because each handler's happy-path inputs differ; what matters is "the request reached the handler," not "the handler returned 200" — that's already pinned by the single-mode tests. * **Gap 2 — `--force` happy path.** The strict re-init regression test (`init_on_existing_graph_uri_does_not_destroy_existing_schema`) pins the error path; nothing pinned the `force: true` escape hatch actually doing what its docstring claims. Add `init_with_force_recovers_from_orphan_schema_files` (`tests/lifecycle.rs`). Writes a bare `_schema.pg` to simulate orphan files from a failed prior init, confirms strict mode bails as expected, then confirms `init_with_options(force: true)` succeeds and produces a functional graph. Note: the test follows the documented semantics — force skips the preflight only, it does NOT purge existing Lance state. An earlier draft of the test (against full overwrite of an existing populated graph) failed because `GraphCoordinator::init` errored on the existing `__manifest`, which is exactly the limitation the `InitOptions::force` docstring already calls out. Recursive purge needs `StorageAdapter::delete_prefix` (tracked separately). Coverage is now fully aligned with the PR's claims. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4120448431
commit
ae4121b7c1
2 changed files with 133 additions and 4 deletions
|
|
@ -2,7 +2,7 @@ mod helpers;
|
|||
|
||||
use std::fs;
|
||||
|
||||
use omnigraph::db::{Omnigraph, ReadTarget};
|
||||
use omnigraph::db::{InitOptions, Omnigraph, ReadTarget};
|
||||
use omnigraph_compiler::schema::parser::parse_schema;
|
||||
use omnigraph_compiler::{build_schema_ir, schema_ir_pretty_json};
|
||||
|
||||
|
|
@ -251,3 +251,56 @@ async fn init_on_existing_graph_uri_does_not_destroy_existing_schema() {
|
|||
"__schema_state.json contents must be preserved when re-init is rejected"
|
||||
);
|
||||
}
|
||||
|
||||
/// Happy-path sibling to the strict re-init regression above:
|
||||
/// `InitOptions { force: true }` must skip the schema-file preflight
|
||||
/// when the operator deliberately wants to recover from orphan
|
||||
/// schema artifacts (e.g. files left behind by a failed prior init).
|
||||
///
|
||||
/// Documented semantics per `InitOptions::force`: skips the preflight
|
||||
/// only. Force does NOT purge existing Lance datasets or `__manifest/`
|
||||
/// — that needs `StorageAdapter::delete_prefix`, which is tracked
|
||||
/// separately. The realistic recovery scenario is "schema files
|
||||
/// exist but Lance state doesn't," which this test reproduces.
|
||||
///
|
||||
/// Without this test, a future refactor could invert the `if !force`
|
||||
/// branch and silently break the operator-facing escape hatch.
|
||||
#[tokio::test]
|
||||
async fn init_with_force_recovers_from_orphan_schema_files() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let uri = dir.path().to_str().unwrap();
|
||||
|
||||
// Simulate orphan schema files: write `_schema.pg` to disk
|
||||
// without running a full init. The preflight will see it and
|
||||
// bail in strict mode.
|
||||
fs::write(dir.path().join("_schema.pg"), TEST_SCHEMA).unwrap();
|
||||
|
||||
// Strict mode refuses because `_schema.pg` exists.
|
||||
let strict_err = match Omnigraph::init(uri, TEST_SCHEMA).await {
|
||||
Ok(_) => panic!("strict init must refuse when orphan _schema.pg exists"),
|
||||
Err(e) => e,
|
||||
};
|
||||
assert!(
|
||||
strict_err.to_string().contains("already initialized"),
|
||||
"strict init must surface AlreadyInitialized (sanity check); got: {strict_err}"
|
||||
);
|
||||
|
||||
// Force init succeeds: it skips the preflight, overwrites the
|
||||
// orphan file, and proceeds to initialize Lance state (which
|
||||
// didn't exist, so `GraphCoordinator::init` is unblocked).
|
||||
let db = Omnigraph::init_with_options(uri, TEST_SCHEMA, InitOptions { force: true })
|
||||
.await
|
||||
.expect("force init must succeed when only orphan schema files block strict init");
|
||||
|
||||
// Confirm the catalog is populated as expected — proves the
|
||||
// graph is functional after force-recovery, not just that the
|
||||
// call returned Ok.
|
||||
assert!(
|
||||
db.catalog().node_types.contains_key("Person"),
|
||||
"force-recovered graph must have the new catalog installed"
|
||||
);
|
||||
assert!(
|
||||
dir.path().join("__schema_state.json").exists(),
|
||||
"force-recovered graph must have full schema state written"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue