chore: checkpoint pi lab rust integration work

This commit is contained in:
Agent Board
2026-07-11 20:39:18 +08:00
parent d47f6447fd
commit d16eccfe10
39 changed files with 4843 additions and 455 deletions
+72 -4
View File
@@ -2622,10 +2622,14 @@ impl ControlPlaneStore for SqliteControlPlaneStore {
let conn = self.lock_conn()?;
let mut stmt = conn.prepare(
"SELECT id, user_id, workspace_id, document_id, session_id, run_id, profile, acp_runtime, event_type, payload_json, created_at
FROM ai_runtime_events
WHERE user_id = ?1 AND run_id = ?2
ORDER BY created_at ASC
LIMIT ?3",
FROM (
SELECT id, user_id, workspace_id, document_id, session_id, run_id, profile, acp_runtime, event_type, payload_json, created_at, rowid AS event_rowid
FROM ai_runtime_events
WHERE user_id = ?1 AND run_id = ?2
ORDER BY created_at DESC, rowid DESC
LIMIT ?3
)
ORDER BY created_at ASC, event_rowid ASC",
)?;
let rows = stmt
.query_map(
@@ -4225,6 +4229,70 @@ mod tests {
.is_empty());
}
#[test]
fn ai_runtime_events_preserve_insert_order_with_same_timestamp() {
let store = store();
create_user(&store, "ai_runtime_order_user");
store
.upsert_ai_runtime_run(UpsertAiRuntimeRunInput {
id: None,
user_id: "ai_runtime_order_user".to_string(),
workspace_id: Some("ws_order".to_string()),
document_id: Some("doc_order".to_string()),
session_id: "sess_order".to_string(),
run_id: "run_order".to_string(),
title: Some("order test".to_string()),
profile: "pi_lab".to_string(),
acp_runtime: "pi".to_string(),
trace_id: None,
status: "running".to_string(),
runtime_json: "{}".to_string(),
payload_json: "{}".to_string(),
})
.expect("insert runtime run");
for (id, payload) in [
("are_z_first", "{\"seq\":1}"),
("are_m_second", "{\"seq\":2}"),
("are_a_third", "{\"seq\":3}"),
] {
store
.append_ai_runtime_event(AppendAiRuntimeEventInput {
id: Some(id.to_string()),
user_id: "ai_runtime_order_user".to_string(),
workspace_id: Some("ws_order".to_string()),
document_id: Some("doc_order".to_string()),
session_id: "sess_order".to_string(),
run_id: "run_order".to_string(),
profile: "pi_lab".to_string(),
acp_runtime: "pi".to_string(),
event_type: "pi_rpc_event".to_string(),
payload_json: payload.to_string(),
})
.expect("append ordered runtime event");
}
let events = store
.list_ai_runtime_events("ai_runtime_order_user", "run_order", 10)
.expect("list runtime events");
assert_eq!(
events
.iter()
.map(|event| event.id.as_str())
.collect::<Vec<_>>(),
vec!["are_z_first", "are_m_second", "are_a_third"]
);
let tail = store
.list_ai_runtime_events("ai_runtime_order_user", "run_order", 2)
.expect("list runtime tail events");
assert_eq!(
tail.iter()
.map(|event| event.id.as_str())
.collect::<Vec<_>>(),
vec!["are_m_second", "are_a_third"]
);
}
#[test]
fn ai_runtime_session_management_renames_auto_titles_and_soft_deletes() {
let store = store();
+8 -4
View File
@@ -3146,10 +3146,14 @@ impl ControlPlaneStore for TursoControlPlaneStore {
let conn = self.lock_conn()?;
let mut stmt = conn.prepare(
"SELECT id, user_id, workspace_id, document_id, session_id, run_id, profile, acp_runtime, event_type, payload_json, created_at
FROM ai_runtime_events
WHERE user_id = ?1 AND run_id = ?2
ORDER BY created_at ASC
LIMIT ?3",
FROM (
SELECT id, user_id, workspace_id, document_id, session_id, run_id, profile, acp_runtime, event_type, payload_json, created_at
FROM ai_runtime_events
WHERE user_id = ?1 AND run_id = ?2
ORDER BY created_at DESC, id DESC
LIMIT ?3
)
ORDER BY created_at ASC, id ASC",
)?;
let rows = stmt
.query_map(