mirror of
https://github.com/affaan-m/ECC.git
synced 2026-12-03 21:51:32 +09:00
fix(ecc2): integrate registered-session activity filtering (#3755)
Preserve harryert source ancestry and skip external session events before deduplication. Strengthen same-ID ordering, late-registration and repeat-sync coverage. Isolate the affected dashboard selection fixture from shared user metrics.
This commit is contained in:
2 files changed
+106
-3
No files matched your search
@@ -2053,6 +2053,16 @@ impl StateStore {
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// The shared Claude tool-activity feed can contain sessions that
|
||||
// were never registered with ECC2 (for example, an existing
|
||||
// standalone Claude Code session). tool_log.session_id has a
|
||||
// foreign key to sessions(id), so ignore those external records
|
||||
// without making the entire sessions/status command fail.
|
||||
// Do this before deduplication: an unknown session must not
|
||||
// reserve an event id for an ECC2-owned session.
|
||||
if !session_tasks.contains_key(&row.session_id) {
|
||||
continue;
|
||||
}
|
||||
if !seen_event_ids.insert(row.id.clone()) {
|
||||
continue;
|
||||
}
|
||||
@@ -6244,6 +6254,92 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_tool_activity_metrics_skips_sessions_not_registered_with_ecc2() -> Result<()> {
|
||||
let tempdir = TestDir::new("store-unregistered-tool-activity")?;
|
||||
let db = StateStore::open(&tempdir.path().join("state.db"))?;
|
||||
let now = Utc::now();
|
||||
db.insert_session(&Session {
|
||||
id: "ecc-owned".to_string(),
|
||||
task: "registered task".to_string(),
|
||||
project: "workspace".to_string(),
|
||||
task_group: "general".to_string(),
|
||||
agent_type: "claude".to_string(),
|
||||
working_dir: PathBuf::from("/tmp"),
|
||||
state: SessionState::Running,
|
||||
pid: None,
|
||||
worktree: None,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
last_heartbeat_at: now,
|
||||
metrics: SessionMetrics::default(),
|
||||
})?;
|
||||
|
||||
let metrics_path = tempdir.path().join("tool-activity.jsonl");
|
||||
fs::write(
|
||||
&metrics_path,
|
||||
concat!(
|
||||
"{\"id\":\"owned-1\",\"session_id\":\"standalone-claude\",\"tool_name\":\"Write\",\"file_paths\":[\"outside.txt\"]}\n",
|
||||
"{\"id\":\"owned-1\",\"session_id\":\"ecc-owned\",\"tool_name\":\"Read\",\"file_paths\":[\"inside.txt\"]}\n"
|
||||
),
|
||||
)?;
|
||||
|
||||
// The orphan deliberately shares the owned event ID, so filtering
|
||||
// after deduplication would incorrectly hide the registered event.
|
||||
// Previously, the first row violated tool_log.session_id's FK and
|
||||
// prevented sessions/status from reading any valid ECC2 sessions.
|
||||
db.sync_tool_activity_metrics(&metrics_path)?;
|
||||
db.sync_tool_activity_metrics(&metrics_path)?;
|
||||
let known = db.get_session("ecc-owned")?.expect("registered session");
|
||||
assert_eq!(known.metrics.tool_calls, 1);
|
||||
assert_eq!(known.metrics.files_changed, 1);
|
||||
let logs = db.query_tool_logs("ecc-owned", 1, 10)?;
|
||||
assert_eq!(logs.total, 1);
|
||||
assert_eq!(logs.entries[0].tool_name, "Read");
|
||||
let total_logs = db
|
||||
.conn
|
||||
.query_row("SELECT COUNT(*) FROM tool_log", [], |r| r.get::<_, i64>(0))?;
|
||||
assert_eq!(total_logs, 1);
|
||||
assert!(db.get_session("standalone-claude")?.is_none());
|
||||
|
||||
// Retain an orphan event until the session is legitimately registered.
|
||||
// The importer must not fabricate a session or permanently discard it.
|
||||
fs::write(
|
||||
&metrics_path,
|
||||
concat!(
|
||||
"{\"id\":\"external-1\",\"session_id\":\"standalone-claude\",\"tool_name\":\"Write\",\"file_paths\":[\"outside.txt\"]}\n",
|
||||
"{\"id\":\"owned-1\",\"session_id\":\"ecc-owned\",\"tool_name\":\"Read\",\"file_paths\":[\"inside.txt\"]}\n"
|
||||
),
|
||||
)?;
|
||||
db.sync_tool_activity_metrics(&metrics_path)?;
|
||||
let registered_later = Session {
|
||||
id: "standalone-claude".to_string(),
|
||||
..known
|
||||
};
|
||||
db.insert_session(®istered_later)?;
|
||||
db.sync_tool_activity_metrics(&metrics_path)?;
|
||||
db.sync_tool_activity_metrics(&metrics_path)?;
|
||||
let later = db
|
||||
.get_session("standalone-claude")?
|
||||
.expect("registered later");
|
||||
assert_eq!(later.metrics.tool_calls, 1);
|
||||
assert_eq!(later.metrics.files_changed, 1);
|
||||
let later_logs = db.query_tool_logs("standalone-claude", 1, 10)?;
|
||||
assert_eq!(later_logs.total, 1);
|
||||
assert_eq!(later_logs.entries[0].tool_name, "Write");
|
||||
let total_logs = db
|
||||
.conn
|
||||
.query_row("SELECT COUNT(*) FROM tool_log", [], |r| r.get::<_, i64>(0))?;
|
||||
assert_eq!(total_logs, 2);
|
||||
let violations =
|
||||
db.conn
|
||||
.query_row("SELECT COUNT(*) FROM pragma_foreign_key_check", [], |row| {
|
||||
row.get::<_, i64>(0)
|
||||
})?;
|
||||
assert_eq!(violations, 0);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_file_activity_expands_logged_file_paths() -> Result<()> {
|
||||
let tempdir = TestDir::new("store-file-activity")?;
|
||||
|
||||
@@ -13057,7 +13057,9 @@ diff --git a/src/lib.rs b/src/lib.rs
|
||||
|
||||
#[test]
|
||||
fn refresh_preserves_selected_session_by_id() -> Result<()> {
|
||||
let db_path = std::env::temp_dir().join(format!("ecc2-dashboard-{}.db", Uuid::new_v4()));
|
||||
let root = std::env::temp_dir().join(format!("ecc2-dashboard-{}", Uuid::new_v4()));
|
||||
fs::create_dir(&root)?;
|
||||
let db_path = root.join("state.db");
|
||||
let db = StateStore::open(&db_path)?;
|
||||
let now = Utc::now();
|
||||
|
||||
@@ -13093,13 +13095,18 @@ diff --git a/src/lib.rs b/src/lib.rs
|
||||
metrics: SessionMetrics::default(),
|
||||
})?;
|
||||
|
||||
let mut dashboard = Dashboard::new(db, Config::default());
|
||||
let cfg = Config {
|
||||
db_path: db_path.clone(),
|
||||
..Config::default()
|
||||
};
|
||||
let mut dashboard = Dashboard::new(db, cfg);
|
||||
dashboard.selected_session = 1;
|
||||
dashboard.sync_selection();
|
||||
dashboard.refresh();
|
||||
|
||||
assert_eq!(dashboard.selected_session_id(), Some("older"));
|
||||
let _ = std::fs::remove_file(db_path);
|
||||
drop(dashboard);
|
||||
fs::remove_dir_all(root)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user