|
1 | 1 | import { describe, it, expect, vi } from "vitest"; |
2 | | -import { extractCommentMemoryEntries, isSafeMemoryId } from "./comment_memory_helpers.cjs"; |
| 2 | +import { extractCommentMemoryEntries, isSafeMemoryId, stripCommentMemoryCodeFence } from "./comment_memory_helpers.cjs"; |
3 | 3 |
|
4 | 4 | describe("comment_memory_helpers", () => { |
5 | 5 | it("extracts managed memory entries", () => { |
| 6 | + const entries = extractCommentMemoryEntries('<gh-aw-comment-memory id="default">\n``````\nhello\n``````\n</gh-aw-comment-memory>'); |
| 7 | + expect(entries).toEqual([{ memoryId: "default", content: "hello" }]); |
| 8 | + }); |
| 9 | + |
| 10 | + it("supports legacy memory entries without code fence markers", () => { |
6 | 11 | const entries = extractCommentMemoryEntries('<gh-aw-comment-memory id="default">\nhello\n</gh-aw-comment-memory>'); |
7 | 12 | expect(entries).toEqual([{ memoryId: "default", content: "hello" }]); |
8 | 13 | }); |
9 | 14 |
|
| 15 | + it("keeps fenced text unchanged when trailing content exists after closing fence", () => { |
| 16 | + const content = "``````\nhello\n``````\ntrailing"; |
| 17 | + expect(stripCommentMemoryCodeFence(content)).toBe(content); |
| 18 | + }); |
| 19 | + |
| 20 | + it("keeps fenced text unchanged when closing fence is missing", () => { |
| 21 | + const content = "``````\nhello"; |
| 22 | + expect(stripCommentMemoryCodeFence(content)).toBe(content); |
| 23 | + }); |
| 24 | + |
| 25 | + it("keeps malformed fenced text unchanged", () => { |
| 26 | + const content = "``````hello\n``````"; |
| 27 | + expect(stripCommentMemoryCodeFence(content)).toBe(content); |
| 28 | + }); |
| 29 | + |
| 30 | + it("strips valid fenced text with extra newlines before content", () => { |
| 31 | + const content = "``````\n\nhello\n``````"; |
| 32 | + expect(stripCommentMemoryCodeFence(content)).toBe("hello"); |
| 33 | + }); |
| 34 | + |
| 35 | + it("strips valid fenced text when content contains six-backtick lines", () => { |
| 36 | + const content = "``````\nline 1\n``````\nline 2\n``````"; |
| 37 | + expect(stripCommentMemoryCodeFence(content)).toBe("line 1\n``````\nline 2"); |
| 38 | + }); |
| 39 | + |
| 40 | + it("keeps fenced text unchanged when closing fence has no leading newline", () => { |
| 41 | + const content = "``````\nhello``````"; |
| 42 | + expect(stripCommentMemoryCodeFence(content)).toBe(content); |
| 43 | + }); |
| 44 | + |
10 | 45 | it("rejects unsafe memory IDs", () => { |
11 | 46 | const warning = vi.fn(); |
12 | 47 | const entries = extractCommentMemoryEntries('<gh-aw-comment-memory id="../bad">\nhello\n</gh-aw-comment-memory>', warning); |
|
0 commit comments