@@ -2,7 +2,7 @@ import fs from 'node:fs';
22import path from 'node:path' ;
33import { fileURLToPath } from 'node:url' ;
44import { assert , beforeEach , expect , test } from '@rstest/core' ;
5- import { create } from '../src' ;
5+ import { create , mergeAgentsFiles } from '../src' ;
66
77const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
88const fixturesDir = path . join ( __dirname , 'fixtures' , 'agents-md' ) ;
@@ -233,3 +233,97 @@ test('should merge top-level sections from AGENTS.md files', async () => {
233233 "
234234 ` ) ;
235235} ) ;
236+
237+ test ( 'mergeAgentsFiles should handle unordered lists without extra newline' , ( ) => {
238+ const file1 = `
239+ ## Tools
240+
241+ - item 1
242+ - item 2
243+ ` ;
244+ const file2 = `
245+ ## Tools
246+
247+ - item 3
248+ ` ;
249+
250+ const merged = mergeAgentsFiles ( [ file1 , file2 ] ) ;
251+
252+ expect ( merged ) . toMatchInlineSnapshot ( `
253+ "## Tools
254+
255+ - item 1
256+ - item 2
257+ - item 3"
258+ ` ) ;
259+ } ) ;
260+
261+ test ( 'mergeAgentsFiles should still add newline for non-list content' , ( ) => {
262+ const file1 = `
263+ ## Tools
264+
265+ Some intro text.
266+ ` ;
267+ const file2 = `
268+ ## Tools
269+
270+ More text.
271+ ` ;
272+
273+ const merged = mergeAgentsFiles ( [ file1 , file2 ] ) ;
274+
275+ expect ( merged ) . toMatchInlineSnapshot ( `
276+ "## Tools
277+
278+ Some intro text.
279+
280+ More text."
281+ ` ) ;
282+ } ) ;
283+
284+ test ( 'mergeAgentsFiles should not skip newline for horizontal rules (---)' , ( ) => {
285+ const file1 = `
286+ ## Tools
287+
288+ ---
289+ ` ;
290+ const file2 = `
291+ ## Tools
292+
293+ - item 1
294+ ` ;
295+
296+ const merged = mergeAgentsFiles ( [ file1 , file2 ] ) ;
297+
298+ expect ( merged ) . toMatchInlineSnapshot ( `
299+ "## Tools
300+
301+ ---
302+
303+ - item 1"
304+ ` ) ;
305+ } ) ;
306+
307+ test ( 'mergeAgentsFiles should add newline when paragraph is followed by list' , ( ) => {
308+ const file1 = `
309+ ## Tools
310+
311+ Some intro text.
312+ ` ;
313+ const file2 = `
314+ ## Tools
315+
316+ - item 1
317+ ` ;
318+
319+ const merged = mergeAgentsFiles ( [ file1 , file2 ] ) ;
320+
321+ // Revised requirement: Paragraph followed by list SHOULD have a newline.
322+ expect ( merged ) . toMatchInlineSnapshot ( `
323+ "## Tools
324+
325+ Some intro text.
326+
327+ - item 1"
328+ ` ) ;
329+ } ) ;
0 commit comments