fix(agent): MCP 读日志/诊断崩溃改走 session_index::event_file(D2 第三处读取点)

M212(M211 复审观察 7 确认的真 bug):

- `agent/ports/events.rs::event_path` 仍在 `root.join("game").join(&entry.log_path)`,
  而 `log_path` 已经是**相对会话根**的 `game/<id>.jsonl` ⇒ 对每个真实会话解析成
  `game/game/<id>.jsonl`。后果是 `ull agent` / MCP 的 read_game_log 与 diagnose_crash
  两个工具对真实会话全报「读会话事件流失败」——内置 AI Agent 的看家本领是坏的。
  现在解析只走 M211 建立的唯一真相源 `session_index::event_file`(新旧两个根都走它)。
- 夹具:`ports/session.rs`、`ports/diagnose.rs` 的索引夹具此前写裸文件名
  `20261029T124501-9f3c2a.jsonl`,与生产差一层 `game/`,所以这个 bug 在测试里永远看不见。
  改成 `session_index::log_path_for(id)` + `session_index::event_file` 落盘。
- 用例:`ports/events.rs` 新增三条(解析结果 = 写入侧落盘的那一个 / 文件缺失时指向的仍是
  生产形状 / 旧根回落走同一套解析);`cli/tests/agent_mcp_stdio_test.rs` 新增一条真机
  MCP 用例(起 `ull agent serve --stdio`,对一份生产形状的会话调 list_game_sessions →
  read_game_log → diagnose_crash)。旧实现下两条路径都红,红的是
  `...\logs\game\game\20261030T101500-abcdef.jsonl`。
This commit is contained in:
AskaEth committed 2026-11-09 14:28:42 +08:00
1 parent 994ffda626
commit fbb4a79955
4 files changed
+197 -13

No files matched your search

+10 -5
View File
@@ -142,10 +142,15 @@ pub fn log_event_json(event: &LogEvent) -> Value {
mod tests {
use super::*;
use std::path::Path;
use unlucky_core::launch::session_index;
/// 生产写入侧真会写出的形状(M212/D2):`log_path` 相对**会话根**,事件流真落点
/// `<根>/game/<id>.jsonl`。夹具以前写裸文件名、把事件流也放在 `game/` 下,
/// 与生产只差一层 `game/` —— 正是这一层让「读取侧多 join 一层」永远测不出来。
fn seed_session(root: &Path) {
let game_dir = root.join("game");
std::fs::create_dir_all(&game_dir).expect("建目录");
let log_path = session_index::log_path_for("20261029T124501-9f3c2a");
let index = session_index::index_path(root);
std::fs::create_dir_all(index.parent().expect("索引父目录")).expect("建目录");
let entry = json!({
"v": 1,
"session_id": "20261029T124501-9f3c2a",
@@ -160,11 +165,11 @@ mod tests {
"silent_failure": false,
"window_detected": true,
"event_count": 2,
"log_path": "20261029T124501-9f3c2a.jsonl",
"log_path": log_path.clone(),
"crash_found": true,
"diagnosis_top": "integrity.forge_missing_library"
});
std::fs::write(game_dir.join("index.jsonl"), format!("{entry}\n")).expect("写索引");
std::fs::write(index, format!("{entry}\n")).expect("写索引");
let events = [
json!({"seq":0,"ts":"2026-10-29T12:45:01.123Z","t_ms":0,"kind":"stdout","payload":{"line":"hi","level":"info"}}),
json!({"seq":1,"ts":"2026-10-29T12:45:02.123Z","t_ms":1000,"kind":"stderr","payload":{"line":"boom","level":"error"}}),
@@ -173,7 +178,7 @@ mod tests {
.iter()
.map(|event| format!("{event}\n"))
.collect::<String>();
std::fs::write(game_dir.join("20261029T124501-9f3c2a.jsonl"), text).expect("写事件");
std::fs::write(session_index::event_file(root, &log_path), text).expect("写事件");
}
#[test]