Files
Marcos Paulo 15d7f5e873 feat: editor blocks and lint, vault knowledge, calendar plugin, macOS menu
- notescraft-lint (rules, safe fixes, learned style) and notescraft-blocks (block model and edits); engine lint.* and block.* commands with CLI and MCP parity
- Lint tab, underlines, slash menu with preview in Source and Visual, block grip and menu, Settings > Editor and lint, Vim block keys
- Visual view: tables, note embeds, %% comments, wrapping property chips
- Vault knowledge (Related tab, assistant sources, Settings) and calendar plugin
- Sidebar top padding fixed, dot grid follows PaperCraft spacing, right-card tabs no longer cover the collapse button

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-18 12:36:00 -03:00

118 lines
6.1 KiB
Rust

//! The calendar tools over MCP: same answers as the engine, the delete flag,
//! the per-plugin toggle and the assistant's short tool list.
mod common;
use common::{ask, call_tool, is_error, registry, seed, temp_vault};
use notescraft_engine::{AppSettings, Session};
use notescraft_mcp::{Server, ServerOptions};
use serde_json::{Value, json};
const LUNCH: &str = "---\ntitle: Lunch\nstart: 2026-10-20T12:00\nend: 2026-10-20T13:00\n---\n";
const CLASH: &str = "---\ntitle: Dentist\nstart: 2026-10-20T12:30\nend: 2026-10-20T13:30\n---\n";
const STANDUP: &str = "---\ntitle: Standup\nstart: 2026-10-19T09:30\nrepeat: weekly\n---\n";
const CALENDAR_TOOLS: [&str; 3] = ["calendar_agenda", "calendar_add", "calendar_edit"];
fn fixture(name: &str, options: ServerOptions, settings: Option<AppSettings>) -> (common::TempVault, Server) {
let vault = temp_vault(name);
seed(vault.path(), &[("Calendar/lunch.md", LUNCH), ("Calendar/clash.md", CLASH), ("Calendar/standup.md", STANDUP)]);
let mut session = Session::open(vault.path()).expect("open");
if let Some(settings) = settings {
session.apply_app_settings(&settings).expect("settings");
}
(vault, Server::new(session, registry(), options))
}
const WRITABLE: ServerOptions = ServerOptions { write: true, allow_delete: false, via_control: false };
fn names(server: &mut Server) -> Vec<String> {
let reply = ask(server, &json!({"jsonrpc": "2.0", "id": 1, "method": "tools/list"}).to_string());
reply["result"]["tools"].as_array().unwrap().iter().map(|t| t["name"].as_str().unwrap().to_owned()).collect()
}
#[test]
fn mcp_and_the_engine_give_the_same_answers() {
let (vault, mut server) = fixture("cal-mcp-parity", WRITABLE, None);
for (tool, id, args) in [
("calendar_agenda", "calendar.agenda", json!({ "from": "2026-10-19", "to": "2026-11-02", "sort": "title" })),
("calendar_free", "calendar.free", json!({ "day": "2026-10-20" })),
("calendar_conflicts", "calendar.conflicts", json!({ "from": "2026-10-19", "to": "2026-10-25" })),
] {
let via_mcp = call_tool(&mut server, tool, &args);
assert!(via_mcp.get("error").is_none(), "{tool}: {via_mcp}");
drop_and_compare(&vault, id, &args, &via_mcp);
}
}
/// The engine's own answer from a read-only session next to the live server.
fn drop_and_compare(vault: &common::TempVault, id: &str, args: &Value, expected: &Value) {
let mut session = Session::open_read_only(vault.path()).expect("read-only session");
let direct = registry().run(id, &mut session, args).expect("engine run");
assert_eq!(&direct, expected, "{id}");
}
#[test]
fn the_assistant_list_holds_three_calendar_tools_and_no_more() {
let options = ServerOptions { via_control: true, ..WRITABLE };
let (_vault, mut server) = fixture("cal-mcp-list", options, None);
let listed = names(&mut server);
assert!(listed.len() <= 24, "a compact list keeps the agent's context small: {listed:?}");
for tool in CALENDAR_TOOLS {
assert!(listed.iter().any(|name| name == tool), "{tool} missing from {listed:?}");
}
let calendar: Vec<&String> = listed.iter().filter(|name| name.starts_with("calendar_")).collect();
assert_eq!(calendar.len(), 3, "{calendar:?}");
}
#[test]
fn a_plain_server_lists_every_calendar_command() {
let (_vault, mut server) = fixture("cal-mcp-plain", WRITABLE, None);
let listed = names(&mut server);
for tool in ["calendar_year", "calendar_review", "calendar_parse", "calendar_filters", "calendar_bulk", "calendar_note", "calendar_filter_save"] {
assert!(listed.iter().any(|name| name == tool), "{tool}");
}
}
#[test]
fn alias_arguments_are_checked_like_the_command() {
let (_vault, mut server) = fixture("cal-mcp-args", WRITABLE, None);
assert!(is_error(&mut server, "calendar_agenda", &json!({ "bogus": 1 })));
assert!(is_error(&mut server, "calendar_edit", &json!({ "id": "Calendar/lunch.md" })), "`fields` is required");
assert!(is_error(&mut server, "calendar_next", &json!({ "limit": "three" })));
}
#[test]
fn a_read_only_server_refuses_calendar_writes_and_the_delete_flag_guards_deletes() {
let (_vault, mut ro) = fixture("cal-mcp-ro", ServerOptions { write: false, ..WRITABLE }, None);
assert!(is_error(&mut ro, "calendar_add", &json!({ "text": "x" })));
assert!(!is_error(&mut ro, "calendar_agenda", &json!({})));
let (vault, mut server) = fixture("cal-mcp-delete", WRITABLE, None);
assert!(is_error(&mut server, "calendar_delete", &json!({ "id": "Calendar/lunch.md" })), "deletes need --allow-delete");
assert!(vault.path().join("Calendar/lunch.md").exists());
let (vault, mut server) = fixture("cal-mcp-delete-ok", ServerOptions { allow_delete: true, ..WRITABLE }, None);
assert!(!is_error(&mut server, "calendar_delete", &json!({ "id": "Calendar/lunch.md" })));
assert!(!vault.path().join("Calendar/lunch.md").exists());
assert!(!is_error(&mut server, "calendar_bulk_delete", &json!({ "ids": ["Calendar/clash.md"], "confirm": true })));
}
#[test]
fn the_plugin_toggle_hides_and_refuses_the_calendar() {
let mut settings = AppSettings::default();
settings.assistant.plugin_tools.insert("calendar".to_owned(), false);
let (_vault, mut off) = fixture("cal-mcp-toggle-off", WRITABLE, Some(settings));
assert!(!names(&mut off).iter().any(|name| name.starts_with("calendar_")), "no calendar tool is listed");
assert!(is_error(&mut off, "calendar_agenda", &json!({})));
let reply =
ask(&mut off, &json!({"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": { "name": "calendar_agenda", "arguments": {} }}).to_string());
assert!(reply.to_string().contains("assistant_plugin_tool_off"), "{reply}");
let mut settings = AppSettings::default();
settings.assistant.plugin_tools.insert("calendar".to_owned(), true);
let (_vault, mut on) = fixture("cal-mcp-toggle-on", WRITABLE, Some(settings));
assert!(!is_error(&mut on, "calendar_agenda", &json!({})));
let (_vault, mut unset) = fixture("cal-mcp-toggle-unset", WRITABLE, None);
assert!(!is_error(&mut unset, "calendar_agenda", &json!({})), "a core plugin is on until switched off");
}