

























@@ -11,6 +11,7 @@ import { prepareSessionManagerForRun } from "../embedded-agent-runner/session-ma
1111import { repairSessionFileIfNeeded } from "../session-file-repair.js";
1212import {
1313CURRENT_SESSION_VERSION,
14+findMostRecentSession,
1415loadEntriesFromFile,
1516SessionManager,
1617type SessionEntry,
@@ -122,6 +123,72 @@ describe("SessionManager.open", () => {
122123expect(entries.filter((entry) => entry.type === "session")).toHaveLength(1);
123124});
124125126+it("continues a valid recent session when the header exceeds the first read chunk", async () => {
127+const dir = await makeTempDir();
128+const sessionFile = path.join(dir, "long-header-session.jsonl");
129+const longCwd = `/tmp/${"deep/".repeat(120)}`;
130+const header = {
131+type: "session",
132+version: CURRENT_SESSION_VERSION,
133+id: "long-header-session",
134+timestamp: "2026-06-18T00:00:00.000Z",
135+cwd: longCwd,
136+};
137+const userEntry = {
138+type: "message",
139+id: "user-1",
140+parentId: null,
141+timestamp: "2026-06-18T00:00:01.000Z",
142+message: { role: "user", content: "resume me" },
143+};
144+await fs.writeFile(
145+sessionFile,
146+`${JSON.stringify(header)}\n${JSON.stringify(userEntry)}\n`,
147+"utf8",
148+);
149+150+expect(Buffer.byteLength(JSON.stringify(header), "utf8")).toBeGreaterThan(512);
151+expect(loadEntriesFromFile(sessionFile)).toHaveLength(2);
152+expect(findMostRecentSession(dir)).toBe(sessionFile);
153+expect(SessionManager.continueRecent(longCwd, dir).getSessionFile()).toBe(sessionFile);
154+});
155+156+it("skips oversized recent session headers instead of hiding valid sessions", async () => {
157+const dir = await makeTempDir();
158+const validSessionFile = path.join(dir, "valid-session.jsonl");
159+const oversizedSessionFile = path.join(dir, "oversized-header-session.jsonl");
160+const validHeader = {
161+type: "session",
162+version: CURRENT_SESSION_VERSION,
163+id: "valid-session",
164+timestamp: "2026-06-18T00:00:00.000Z",
165+cwd: "/tmp/task-repo",
166+};
167+const oversizedHeader = {
168+type: "session",
169+version: CURRENT_SESSION_VERSION,
170+id: "oversized-header-session",
171+timestamp: "2026-06-18T00:00:01.000Z",
172+cwd: `/tmp/${"deep/".repeat(14_000)}`,
173+};
174+175+await fs.writeFile(validSessionFile, `${JSON.stringify(validHeader)}\n`, "utf8");
176+await fs.writeFile(oversizedSessionFile, `${JSON.stringify(oversizedHeader)}\n`, "utf8");
177+await fs.utimes(
178+validSessionFile,
179+new Date("2026-06-18T00:00:00.000Z"),
180+new Date("2026-06-18T00:00:00.000Z"),
181+);
182+await fs.utimes(
183+oversizedSessionFile,
184+new Date("2026-06-18T00:00:01.000Z"),
185+new Date("2026-06-18T00:00:01.000Z"),
186+);
187+188+expect(Buffer.byteLength(JSON.stringify(oversizedHeader), "utf8")).toBeGreaterThan(64 * 1024);
189+expect(findMostRecentSession(dir)).toBe(validSessionFile);
190+});
191+125192it("still migrates old transcript versions while bypassing the warm cache", async () => {
126193const dir = await makeTempDir();
127194const sessionFile = path.join(dir, "session.jsonl");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。