mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 23:36:20 +00:00
fix(mcp): harden stdio opens, commits and user-supplied ranges
- Check per call that synapse.db exists and is on this binary's schema, so the stdio server never migrates or re-stamps the app's live database. - Keep the transaction open (rolled back on drop) when COMMIT fails. - Reject dates outside years 1000-9999 and oversized cursors (overflow). - core: export SCHEMA_VERSION. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0253cd4180
commit
4195374c23
5 files changed
+115
-4
No files matched your search
@@ -161,3 +161,36 @@ fn refuses_a_missing_graph() {
|
||||
assert!(!out.status.success());
|
||||
assert!(!dir.path().join("nope").exists(), "must not create a graph");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refuses_a_graph_on_another_schema() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
{
|
||||
let g = Graph::open(dir.path()).unwrap();
|
||||
g.conn()
|
||||
.execute("UPDATE meta SET value='1' WHERE key='schema'", [])
|
||||
.unwrap();
|
||||
}
|
||||
let mut s = Server::start(dir.path(), &[]);
|
||||
s.init();
|
||||
let r = s.call(
|
||||
2,
|
||||
"tools/call",
|
||||
json!({"name": "list_pages", "arguments": {}}),
|
||||
);
|
||||
let text = r["result"]["content"][0]["text"].as_str().unwrap();
|
||||
assert!(text.contains("schema is v1"), "{r}");
|
||||
drop(s);
|
||||
let g = Graph::open(dir.path()).unwrap();
|
||||
let v: String = g
|
||||
.conn()
|
||||
.query_row("SELECT value FROM meta WHERE key='schema'", [], |r| {
|
||||
r.get(0)
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
v,
|
||||
synapse_core::SCHEMA_VERSION.to_string(),
|
||||
"re-opened by core only here"
|
||||
);
|
||||
}
|
||||
@@ -620,3 +620,28 @@ fn resources_render_pages() {
|
||||
let out = read(&g, |g| tools::page_resource(g, "Dune"));
|
||||
assert!(out.contains("- Arrakis is a desert planet\n"), "{out}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extreme_dates_and_cursors_are_rejected() {
|
||||
let (_d, g) = fixture();
|
||||
let e = read_err(&g, |g| {
|
||||
tools::timeline(
|
||||
g,
|
||||
&RangeParams {
|
||||
from: None,
|
||||
to: Some("-262143-01-03".into()),
|
||||
},
|
||||
)
|
||||
});
|
||||
assert!(e.contains("bad date"), "{e}");
|
||||
let e = read_err(&g, |g| {
|
||||
tools::list_pages(
|
||||
g,
|
||||
&ListPagesParams {
|
||||
cursor: Some(usize::MAX.to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
});
|
||||
assert!(e.contains("bad cursor"), "{e}");
|
||||
}
|
||||
Reference in new issue
Block a user