refactor(memory_sync): convert GitHub + Linear to the generic sync orchestrator (Refs #3333, stacked on #3852) (#3860)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
This commit is contained in:
sanil-23
2026-06-21 15:20:30 -07:00
committed by GitHub
co-authored by Claude Steven Enamakel
parent 6d220a7b2a
commit b4a2242266
8 changed files with 911 additions and 1056 deletions
@@ -1293,6 +1293,86 @@ async fn linear_sync_max_items_caps_ingest_to_exact_count() {
server.abort();
}
// ─────────────────────────────────────────────────────────────────────────
// Linear sync_depth_days enforcement (via the shared orchestrator)
//
// Linear applies the depth window client-side (RFC3339 `updatedAt`). The mock
// returns 2 recent issues (far-future) + 3 ancient (year-2000) in descending
// order; with sync_depth_days=7 only the 2 recent issues persist — the
// orchestrator truncates the page at the first item below the floor.
// ─────────────────────────────────────────────────────────────────────────
/// Build `recent` + `old` Linear issues in descending `updatedAt` order.
fn linear_depth_issues(recent: usize, old: usize) -> Vec<Value> {
let mut issues = Vec::new();
for i in 0..recent {
issues.push(json!({
"id": format!("linear-recent-{i:04}"),
"identifier": format!("ENG-R{i}"),
"title": format!("Recent {i}"),
"updatedAt": format!("2099-12-{:02}T10:00:00.000Z", 28 - i),
"url": format!("https://linear.app/cap/issue/ENG-R{i}"),
"description": "recent",
}));
}
for i in 0..old {
issues.push(json!({
"id": format!("linear-old-{i:04}"),
"identifier": format!("ENG-O{i}"),
"title": format!("Old {i}"),
"updatedAt": format!("2000-01-{:02}T10:00:00.000Z", 3 - i),
"url": format!("https://linear.app/cap/issue/ENG-O{i}"),
"description": "old",
}));
}
issues
}
#[tokio::test]
async fn linear_sync_depth_days_filters_old_issues() {
let _guard = env_lock();
let tmp = TempDir::new().expect("tempdir");
let _workspace = EnvGuard::set_path("OPENHUMAN_WORKSPACE", tmp.path());
let _home = EnvGuard::set_path("HOME", tmp.path());
let _backend = EnvGuard::unset("BACKEND_URL");
// One page: 2 recent + 3 ancient. With a 7-day window only the 2 recent
// issues must be ingested.
let requests: Arc<Mutex<Vec<Value>>> = Arc::new(Mutex::new(Vec::new()));
let (base, server) = loopback_router(linear_cap_router(
linear_depth_issues(2, 3),
Arc::clone(&requests),
))
.await;
let mut config = config_in(&tmp);
config.api_url = Some(base);
persist_config(&config).await;
store_session(&config);
memory_global::init(config.workspace_dir.clone()).expect("init global memory");
let ctx = ProviderContext {
config: Arc::new(config),
toolkit: "linear".to_string(),
connection_id: Some("conn-linear-depth".to_string()),
usage: Default::default(),
max_items: None,
sync_depth_days: Some(7),
};
let outcome = LinearProvider::new()
.sync(&ctx, SyncReason::ConnectionCreated)
.await
.expect("linear depth sync");
assert_eq!(
outcome.items_ingested, 2,
"sync_depth_days=7 must drop the 3 year-2000 issues and keep the 2 recent ones"
);
server.abort();
}
// ─────────────────────────────────────────────────────────────────────────
// ClickUp cap enforcement
//