Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions crates/context-cli/tests/mcp_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ async fn test_note_list_empty() {
note_type: None,
limit: None,
offset: None,
include_content: None,
sort: None,
order: None,
};
Expand Down Expand Up @@ -314,7 +313,6 @@ async fn test_note_list_with_data() {
note_type: None,
limit: None,
offset: None,
include_content: None,
sort: None,
order: None,
};
Expand All @@ -329,6 +327,10 @@ async fn test_note_list_with_data() {
};
let response: serde_json::Value = serde_json::from_str(content_text).unwrap();
assert_eq!(response["total"], 1);
assert_eq!(
response["items"][0]["content"], "",
"list results must project to metadata"
);
}

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -361,7 +363,6 @@ async fn test_note_list_search() {
note_type: None,
limit: None,
offset: None,
include_content: None,
sort: None,
order: None,
};
Expand All @@ -376,6 +377,10 @@ async fn test_note_list_search() {
};
let response: serde_json::Value = serde_json::from_str(content_text).unwrap();
assert_eq!(response["total"], 1);
assert_eq!(
response["items"][0]["content"], "",
"search results must project to metadata"
);
}

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -410,7 +415,6 @@ async fn test_note_list_pagination() {
note_type: None,
limit: Some(1),
offset: None,
include_content: None,
sort: None,
order: None,
};
Expand Down Expand Up @@ -458,7 +462,6 @@ async fn test_note_list_tag_filter() {
note_type: None,
limit: None,
offset: None,
include_content: None,
sort: None,
order: None,
};
Expand Down Expand Up @@ -521,7 +524,6 @@ async fn test_note_list_with_project_id_filter() {
note_type: None,
limit: None,
offset: None,
include_content: None,
sort: None,
order: None,
};
Expand Down Expand Up @@ -584,7 +586,6 @@ async fn test_note_list_with_parent_id_filter() {
note_type: None,
limit: None,
offset: None,
include_content: None,
sort: None,
order: None,
};
Expand Down Expand Up @@ -648,7 +649,6 @@ async fn test_note_list_with_note_type_filter() {
note_type: Some("task".to_string()),
limit: None,
offset: None,
include_content: None,
sort: None,
order: None,
};
Expand Down Expand Up @@ -693,7 +693,6 @@ async fn test_note_list_sorting() {
note_type: None,
limit: None,
offset: None,
include_content: None,
sort: Some("title".to_string()),
order: Some("asc".to_string()),
};
Expand Down
107 changes: 107 additions & 0 deletions crates/context-cli/tests/mcp_skills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,110 @@ async fn test_skill_update_invalidates_cache() {
// Cleanup - TempDir removes itself on drop
let _ = skills_dir;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_skill_list_omits_content_by_default() {
let db = setup_db().await;
let skill = Skill {
id: "skill001".to_string(),
name: "test-skill".to_string(),
description: "A test skill".to_string(),
content: "---\nname: test-skill\n---\n# Test\n\nTest content".to_string(),
tags: vec!["test".to_string()],
project_ids: vec![],
scripts: vec![],
references: vec![],
assets: vec![],
created_at: Some("2025-01-01 00:00:00".to_string()),
updated_at: Some("2025-01-01 00:00:00".to_string()),
deleted_at: None,
source: None,
source_subpath: None,
};
db.skills().create(&skill).await.unwrap();
let db = Arc::new(db);
let tools = SkillTools::new(
db.clone(),
ChangeNotifier::new(),
get_data_dir().join("skills"),
);

let params = ListSkillsParams {
query: None,
tags: None,
project_id: None,
limit: None,
offset: None,
sort: None,
order: None,
};

let result = tools.skill_list(Parameters(params)).await;
assert!(result.is_ok());

let call_result = result.unwrap();
let content_text = match &call_result.content[0] {
ContentBlock::Text(text) => text.text.as_str(),
_ => panic!("Expected text content"),
};
let response: serde_json::Value = serde_json::from_str(content_text).unwrap();
assert_eq!(response["total"], 1);
assert_eq!(
response["items"][0]["content"], "",
"skill_list without include_content must omit content"
);
assert_eq!(response["items"][0]["name"], "test-skill");
}

#[tokio::test(flavor = "multi_thread")]
async fn test_skill_list_search_returns_metadata_only() {
let db = setup_db().await;
let skill = Skill {
id: "skill001".to_string(),
name: "test-skill".to_string(),
description: "A test skill".to_string(),
content: "---\nname: test-skill\n---\n# Test\n\nTest content".to_string(),
tags: vec!["test".to_string()],
project_ids: vec![],
scripts: vec![],
references: vec![],
assets: vec![],
created_at: Some("2025-01-01 00:00:00".to_string()),
updated_at: Some("2025-01-01 00:00:00".to_string()),
deleted_at: None,
source: None,
source_subpath: None,
};
db.skills().create(&skill).await.unwrap();
let db = Arc::new(db);
let tools = SkillTools::new(
db.clone(),
ChangeNotifier::new(),
get_data_dir().join("skills"),
);

let params = ListSkillsParams {
query: Some("Test content".to_string()),
tags: None,
project_id: None,
limit: None,
offset: None,
sort: None,
order: None,
};

let result = tools.skill_list(Parameters(params)).await;
assert!(result.is_ok());

let call_result = result.unwrap();
let content_text = match &call_result.content[0] {
ContentBlock::Text(text) => text.text.as_str(),
_ => panic!("Expected text content"),
};
let response: serde_json::Value = serde_json::from_str(content_text).unwrap();
assert_eq!(response["total"], 1);
assert_eq!(
response["items"][0]["content"], "",
"search results must project to metadata"
);
}
121 changes: 121 additions & 0 deletions crates/context-cli/tests/mcp_task_lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,127 @@ async fn test_task_list_list_with_data() {
assert_eq!(response["total"], 1);
}

const LIST_NOTES: &str = "## Context\n\nThis container note block is deliberately longer than one line so that a null response field is easy to distinguish from the stored value.\n\n## Decisions\n\nKeep the notes out of list payloads.";

fn make_list_with_notes(id: &str, project_id: &str) -> TaskList {
TaskList {
id: id.to_string(),
title: "Notes List".to_string(),
description: Some("Short description".to_string()),
tags: vec![],
external_refs: vec![],
status: TaskListStatus::Active,
notes: Some(LIST_NOTES.to_string()),
repo_ids: vec![],
project_id: project_id.to_string(),
created_at: Some("2025-01-01 00:00:00".to_string()),
updated_at: Some("2025-01-01 00:00:00".to_string()),
archived_at: None,
deleted_at: None,
}
}

fn tool_json(result: CallToolResult) -> serde_json::Value {
let content_text = match &result.content[0] {
ContentBlock::Text(text) => text.text.as_str(),
_ => panic!("Expected text content"),
};
serde_json::from_str(content_text).unwrap()
}

#[tokio::test(flavor = "multi_thread")]
async fn test_task_list_list_omits_notes() {
let db = setup_db().await;
let project_id = create_test_project(&db).await;
db.task_lists()
.create(&make_list_with_notes("list0001", &project_id))
.await
.unwrap();
let db = Arc::new(db);
let tools = TaskListTools::new(db.clone(), ChangeNotifier::new());

let params = ListTaskListsParams {
query: None,
tags: None,
status: None,
project_id: None,
limit: None,
offset: None,
sort: None,
order: None,
};

let response = tool_json(tools.task_list_list(Parameters(params)).await.unwrap());

assert_eq!(response["total"], 1);
assert!(
response["items"][0]["notes"].is_null(),
"task_list_list must omit notes, got: {}",
response["items"][0]["notes"]
);
assert_eq!(
response["items"][0]["description"], "Short description",
"description stays in list responses"
);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_task_list_list_search_omits_notes() {
let db = setup_db().await;
let project_id = create_test_project(&db).await;
let mut list = make_list_with_notes("list0001", &project_id);
list.title = "Rust Container".to_string();
db.task_lists().create(&list).await.unwrap();
let db = Arc::new(db);
let tools = TaskListTools::new(db.clone(), ChangeNotifier::new());

let params = ListTaskListsParams {
query: Some("rust".to_string()),
tags: None,
status: None,
project_id: None,
limit: None,
offset: None,
sort: None,
order: None,
};

let response = tool_json(tools.task_list_list(Parameters(params)).await.unwrap());

assert_eq!(response["total"], 1);
assert!(
response["items"][0]["notes"].is_null(),
"search results must omit notes, got: {}",
response["items"][0]["notes"]
);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_task_list_get_returns_notes() {
let db = setup_db().await;
let project_id = create_test_project(&db).await;
db.task_lists()
.create(&make_list_with_notes("list0001", &project_id))
.await
.unwrap();
let db = Arc::new(db);
let tools = TaskListTools::new(db.clone(), ChangeNotifier::new());

let response = tool_json(
tools
.task_list_get(Parameters(GetTaskListParams {
id: "list0001".to_string(),
}))
.await
.unwrap(),
);

assert_eq!(
response["notes"], LIST_NOTES,
"single-entity get must keep the stored notes"
);
}

#[tokio::test(flavor = "multi_thread")]
async fn test_task_list_list_pagination() {
let db = setup_db().await;
Expand Down
Loading
Loading