second-brain-api 0.13.5

HTTP API server for second-brain: REST endpoints for recall, remember, and ingest
Documentation
mod common;

use axum::http::StatusCode;
use tower::ServiceExt;

use common::{app_with_store, json_body, post_json};
use second_brain_core::schema::{Memory, MemoryType};
use second_brain_core::store::Store;

fn memory(content: &str, source: &str, project: Option<&str>) -> Memory {
    Memory::new(
        content.to_string(),
        MemoryType::Semantic,
        source.to_string(),
        String::new(),
    )
    .with_project_path(project.map(str::to_string))
}

async fn context(app: &axum::Router, project: &str) -> serde_json::Value {
    let response = app
        .clone()
        .oneshot(post_json(
            "/v1/context",
            serde_json::json!({"project": project}),
        ))
        .await
        .unwrap();
    assert_eq!(response.status(), StatusCode::OK);
    json_body(response).await
}

#[tokio::test]
async fn context_for_an_unfiled_project_does_not_scan_transcript_text() {
    let (app, store) = app_with_store();
    store
        .store_memory(&memory(
            "we talked about wardrobe pricing",
            "claude-code",
            Some("space"),
        ))
        .unwrap();

    let body = context(&app, "wardrobe").await;
    assert_eq!(body["memories"].as_array().unwrap().len(), 0);
}

#[tokio::test]
async fn context_returns_live_project_memories_only() {
    let (app, store) = app_with_store();
    let live = memory("wardrobe uses fastapi", "api", Some("wardrobe"));
    let retired = memory("wardrobe used flask", "api", Some("wardrobe"));
    store.store_memory(&live).unwrap();
    store.store_memory(&retired).unwrap();
    store.retire_memory(retired.id, "outdated").unwrap();

    let body = context(&app, "wardrobe").await;
    let ids: Vec<&str> = body["memories"]
        .as_array()
        .unwrap()
        .iter()
        .map(|m| m["id"].as_str().unwrap())
        .collect();
    assert_eq!(ids, vec![live.id.to_string()]);
}