import { describe, expect, test } from 'bun:test' import { stripHtmlComments, isMemoryFilePath, getLargeMemoryFiles, MAX_MEMORY_CHARACTER_COUNT, type MemoryFileInfo, } from '../claudemd' function mockMemoryFile( overrides: Partial = {}, ): MemoryFileInfo { return { path: '/project/CLAUDE.md', type: 'Project', content: 'test content', ...overrides, } } describe('stripHtmlComments', () => { test('strips block-level HTML comments (own line)', () => { // CommonMark type-2 HTML blocks: comment must start at beginning of line const result = stripHtmlComments('text\n\nmore') expect(result.content).not.toContain('block comment') expect(result.stripped).toBe(true) }) test('returns stripped: false when no comments', () => { const result = stripHtmlComments('no comments here') expect(result.stripped).toBe(false) expect(result.content).toBe('no comments here') }) test('returns stripped: true when block comments exist', () => { const result = stripHtmlComments('hello\n\nend') expect(result.stripped).toBe(true) }) test('handles empty string', () => { const result = stripHtmlComments('') expect(result.content).toBe('') expect(result.stripped).toBe(false) }) test('handles multiple block comments', () => { const result = stripHtmlComments('a\n\nb\n\nc') expect(result.content).not.toContain('c1') expect(result.content).not.toContain('c2') expect(result.stripped).toBe(true) }) test('preserves code block content', () => { const input = 'text\n```html\n\n```\nmore' const result = stripHtmlComments(input) expect(result.content).toContain('') }) test('preserves inline comments within paragraphs', () => { // Inline comments are NOT stripped (CommonMark paragraph semantics) const result = stripHtmlComments('text more') expect(result.content).toContain('') expect(result.stripped).toBe(false) }) test('leaves unclosed HTML comment unchanged', () => { const result = stripHtmlComments('some text') expect(result.content).toContain('some text') expect(result.content).not.toContain('