fix(core): serialize Trace appends; tolerate malformed middle lines on read (#234)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Yaowei Zheng
2026-08-07 17:49:40 +08:00
committed by GitHub
parent 9745773cb9
commit 4a899a265f
9 changed files with 344 additions and 33 deletions
@@ -189,7 +189,10 @@ describe("trace-import-export", () => {
it("import: malformed middle line → 400 invalid_trace", async () => {
const lines = toContent(sampleTrace(SID)).split("\n");
lines[1] = "{not json"; // corrupt a middle line (non-final: parseTraceLines throws loudly)
// Corrupt a middle (non-final) line. Read paths skip malformed middle lines (#215
// recovery), but import validates strictly (onMalformed: "throw") — damage in an
// uploaded file is reported, not silently dropped.
lines[1] = "{not json";
const res = await owner.post(`${base()}/import`, { dataBase64: b64(lines.join("\n")) });
expect(res.status).toBe(400);
expect(await errorCode(res)).toBe("invalid_trace");