11using System . Text . Json ;
22using System . Text . Json . Nodes ;
3+ using System . Text . Json . Serialization . Metadata ;
34using CodeIndex . Cli ;
45using CodeIndex . Database ;
6+ using CodeIndex . Models ;
57
68namespace CodeIndex . Tests ;
79
@@ -22,6 +24,7 @@ public class JsonOutputSnapshotTests
2224 private readonly JsonSerializerOptions _jsonOptions = new ( )
2325 {
2426 PropertyNamingPolicy = JsonNamingPolicy . SnakeCaseLower ,
27+ TypeInfoResolver = new DefaultJsonTypeInfoResolver ( ) ,
2528 } ;
2629
2730 private const string LibSource = @"namespace Demo;
@@ -233,6 +236,52 @@ public void RunExcerpt_JsonOutput_MatchesGolden()
233236 }
234237 }
235238
239+ [ Fact ]
240+ public void RunSuggestionsCompact_JsonOutput_MatchesGolden_Issue5061 ( )
241+ {
242+ var projectRoot = TestProjectHelper . CreateTempProject ( "cdidx_snapshot_suggestions_compact" ) ;
243+ try
244+ {
245+ var cdidxDir = Path . Combine ( projectRoot , ".cdidx" ) ;
246+ Directory . CreateDirectory ( cdidxDir ) ;
247+ var dbPath = Path . Combine ( cdidxDir , "codeindex.db" ) ;
248+ var titlePrefix = new string ( 'a' , 118 ) ;
249+ var store = new SuggestionStore ( cdidxDir ) ;
250+ Assert . True ( store . TryAdd ( new SuggestionRecord
251+ {
252+ Id = new string ( '1' , 64 ) ,
253+ Category = "output_format" ,
254+ Language = "csharp" ,
255+ Description = "Snapshot query description" ,
256+ SampledTitle = titlePrefix + "😀suffix" ,
257+ EvidencePaths = [ "src/Snapshot.cs" ] ,
258+ CreatedAt = new DateTime ( 2026 , 8 , 11 , 0 , 0 , 0 , DateTimeKind . Utc ) ,
259+ } ) ) ;
260+
261+ var ( exitCode , stdout , stderr ) = CaptureConsole ( ( ) => SuggestionsCommandRunner . Run (
262+ [ "list" , "--db" , dbPath , "--query" , "snapshot query" , "--compact" ] ,
263+ _jsonOptions ) ) ;
264+
265+ Assert . Equal ( CommandExitCodes . Success , exitCode ) ;
266+ Assert . Equal ( string . Empty , stderr ) ;
267+ using var document = JsonDocument . Parse ( stdout ) ;
268+ var item = Assert . Single ( document . RootElement . GetProperty ( "results" ) . EnumerateArray ( ) ) ;
269+ var compactTitle = item . GetProperty ( "title" ) . GetString ( )
270+ ?? throw new InvalidOperationException ( "Compact suggestion title was null." ) ;
271+ Assert . Equal ( titlePrefix + "..." , compactTitle ) ;
272+ Assert . DoesNotContain ( '\uFFFD ' , compactTitle ) ;
273+
274+ JsonOutputSnapshotHelper . AssertMatches (
275+ "suggestions-compact.json" ,
276+ stdout ,
277+ BuildPathReplacements ( projectRoot ) ) ;
278+ }
279+ finally
280+ {
281+ TestProjectHelper . DeleteDirectory ( projectRoot ) ;
282+ }
283+ }
284+
236285 private static void MarkGraphAndFoldReady ( string dbPath )
237286 {
238287 using var db = new DbContext ( DbOpenIntent . WriteIndex , dbPath ) ;
0 commit comments