diff --git a/src/tools/council-archive/council-response-extractor.test.ts b/src/tools/council-archive/council-response-extractor.test.ts index 13a6c5f18..d436d2a0b 100644 --- a/src/tools/council-archive/council-response-extractor.test.ts +++ b/src/tools/council-archive/council-response-extractor.test.ts @@ -228,4 +228,52 @@ describe("extractCouncilResponse", () => { }) }) }) + + describe("#given CRLF line endings throughout the response", () => { + it("#then extracts content correctly with \\r\\n line endings", () => { + const content = "a".repeat(100) + const text = `\r\n${content}\r\n` + const result = extractCouncilResponse(text) + + expect(result).toEqual({ + has_response: true, + response_complete: true, + result: content, + }) + }) + }) + + describe("#given closing tag followed by \\r\\n", () => { + it("#then recognizes the closing tag as structural", () => { + const content = "a".repeat(100) + const text = `${content}\r\nsome trailing text` + const result = extractCouncilResponse(text) + + expect(result).toEqual({ + has_response: true, + response_complete: true, + result: content, + }) + }) + }) + + describe("#given mixed \\n and \\r\\n line endings", () => { + it("#then extracts content correctly regardless of mixed line endings", () => { + const longLine = "a".repeat(80) + const text = [ + "", + "## Finding 1: Mixed endings", + longLine, + "", + ].join("\r\n") + const result = extractCouncilResponse(text) + + expect(result).toEqual({ + has_response: true, + response_complete: true, + result: `## Finding 1: Mixed endings\r\n${longLine}`, + }) + }) + }) }) + diff --git a/src/tools/council-archive/council-response-extractor.ts b/src/tools/council-archive/council-response-extractor.ts index 6c5aba9a9..b71916856 100644 --- a/src/tools/council-archive/council-response-extractor.ts +++ b/src/tools/council-archive/council-response-extractor.ts @@ -45,7 +45,7 @@ function isStructuralOpen(text: string, idx: number): boolean { function isStructuralClose(text: string, idx: number): boolean { const afterIdx = idx + CLOSING_TAG.length - return afterIdx === text.length || text[afterIdx] === "\n" + return afterIdx === text.length || text[afterIdx] === "\n" || text[afterIdx] === "\r" } function findLastStructuralClose(text: string): number {