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:
1 parent
994ffda626
commit
fbb4a79955
4 files changed
+197
-13
No files matched your search
@@ -128,13 +128,17 @@ impl DiagnosePort for CoreDiagnose {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
use unlucky_core::launch::session_index;
|
||||
|
||||
/// 与生产写入同形(M212/D2):`log_path` 相对会话根,事件流落在 `<根>/game/<id>.jsonl`。
|
||||
fn seed(root: &std::path::Path, stderr_line: &str) {
|
||||
let game = root.join("game");
|
||||
std::fs::create_dir_all(&game).expect("建目录");
|
||||
let sid = "20261029T124501-9f3c2a";
|
||||
let log_path = session_index::log_path_for(sid);
|
||||
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",
|
||||
"session_id": sid,
|
||||
"instance_id": "inst-1",
|
||||
"instance_name": "1.20.1 Forge",
|
||||
"game_version": "1.20.1",
|
||||
@@ -146,18 +150,18 @@ mod tests {
|
||||
"silent_failure": false,
|
||||
"window_detected": false,
|
||||
"event_count": 1,
|
||||
"log_path": "20261029T124501-9f3c2a.jsonl",
|
||||
"log_path": log_path.clone(),
|
||||
"crash_found": true,
|
||||
"diagnosis_top": null
|
||||
});
|
||||
std::fs::write(game.join("index.jsonl"), format!("{entry}\n")).expect("写索引");
|
||||
std::fs::write(index, format!("{entry}\n")).expect("写索引");
|
||||
let event = json!({
|
||||
"seq": 0, "ts": "2026-10-29T12:45:01.123Z", "t_ms": 0,
|
||||
"kind": "stderr",
|
||||
"payload": { "line": stderr_line, "level": "error" }
|
||||
});
|
||||
std::fs::write(
|
||||
game.join("20261029T124501-9f3c2a.jsonl"),
|
||||
session_index::event_file(root, &log_path),
|
||||
format!("{event}\n"),
|
||||
)
|
||||
.expect("写事件");
|
||||
|
||||
Reference in new issue
Block a user