@@ -1982,6 +1982,39 @@ describe("oversized transcript line guards", () => {
|
1982 | 1982 | expectUsageFields(usage, { modelProvider: "test-provider" }); |
1983 | 1983 | }); |
1984 | 1984 | |
| 1985 | +test("oversized line metadata extraction preserves id and parentId", async () => { |
| 1986 | +const sessionId = "test-oversized-metadata-extract"; |
| 1987 | +const transcriptPath = path.join(tmpDir, `${sessionId}.jsonl`); |
| 1988 | +const oversizedContent = "w".repeat(300 * 1024); |
| 1989 | +const lines = [ |
| 1990 | +JSON.stringify({ type: "session", version: 3, id: sessionId }), |
| 1991 | +JSON.stringify({ |
| 1992 | +type: "message", |
| 1993 | +id: "root-msg", |
| 1994 | +parentId: null, |
| 1995 | +message: { role: "user", content: "root" }, |
| 1996 | +}), |
| 1997 | +JSON.stringify({ |
| 1998 | +type: "message", |
| 1999 | +id: "oversized-child", |
| 2000 | +parentId: "root-msg", |
| 2001 | +message: { role: "assistant", content: oversizedContent }, |
| 2002 | +}), |
| 2003 | +]; |
| 2004 | +fs.writeFileSync(transcriptPath, `${lines.join("\n")}\n`, "utf-8"); |
| 2005 | + |
| 2006 | +const out = await readRecentSessionMessagesAsync(sessionId, storePath, undefined, { |
| 2007 | +maxMessages: 10, |
| 2008 | +}); |
| 2009 | + |
| 2010 | +const serialized = JSON.stringify(out); |
| 2011 | +// The oversized line's id and parentId must be extracted correctly |
| 2012 | +// from the prefix via regex-based field extraction. |
| 2013 | +expect(serialized).toContain("oversized-child"); |
| 2014 | +expect(serialized).toContain("root-msg"); |
| 2015 | +expect(serialized).not.toContain(oversizedContent); |
| 2016 | +}); |
| 2017 | + |
1985 | 2018 | test("readSessionTitleFieldsFromTranscriptAsync delegates to bounded sync reader", async () => { |
1986 | 2019 | const sessionId = "test-async-title-bounded"; |
1987 | 2020 | writeTranscript( |
|