@@ -267,6 +267,112 @@ suite('ChartBigNumberBlockConverter', () => {
267267 assert . doesNotHaveAnyKeys ( block . metadata , [ DEEPNOTE_VSCODE_RAW_CONTENT_KEY ] ) ;
268268 } ) ;
269269
270+ test ( 'preserves comparison metadata when updating value' , ( ) => {
271+ const block : DeepnoteBlock = {
272+ blockGroup : 'test-group' ,
273+ content : 'old content' ,
274+ id : 'block-123' ,
275+ metadata : {
276+ deepnote_big_number_value : 'old_value' ,
277+ deepnote_big_number_title : 'My Number' ,
278+ deepnote_big_number_format : 'number' ,
279+ deepnote_big_number_comparison_enabled : true ,
280+ deepnote_big_number_comparison_type : 'percentage-change' ,
281+ deepnote_big_number_comparison_value : 'baseline_value' ,
282+ deepnote_big_number_comparison_title : 'vs baseline' ,
283+ deepnote_big_number_comparison_format : 'percent'
284+ } ,
285+ sortingKey : 'a0' ,
286+ type : 'big-number'
287+ } ;
288+ const cell = new NotebookCellData ( NotebookCellKind . Code , 'new_value' , 'python' ) ;
289+
290+ converter . applyChangesToBlock ( block , cell ) ;
291+
292+ assert . strictEqual ( block . content , '' ) ;
293+ assert . strictEqual ( block . metadata ?. deepnote_big_number_value , 'new_value' ) ;
294+ // Comparison metadata should be preserved
295+ assert . strictEqual ( block . metadata ?. deepnote_big_number_comparison_enabled , true ) ;
296+ assert . strictEqual ( block . metadata ?. deepnote_big_number_comparison_type , 'percentage-change' ) ;
297+ assert . strictEqual ( block . metadata ?. deepnote_big_number_comparison_value , 'baseline_value' ) ;
298+ assert . strictEqual ( block . metadata ?. deepnote_big_number_comparison_title , 'vs baseline' ) ;
299+ assert . strictEqual ( block . metadata ?. deepnote_big_number_comparison_format , 'percent' ) ;
300+ } ) ;
301+
302+ test ( 'round-trip: block with comparison → cell → block preserves comparison metadata' , ( ) => {
303+ // Start with a block that has comparison enabled
304+ const originalBlock : DeepnoteBlock = {
305+ blockGroup : 'test-group' ,
306+ content : '' ,
307+ id : 'block-123' ,
308+ metadata : {
309+ deepnote_big_number_value : 'revenue' ,
310+ deepnote_big_number_title : 'Revenue' ,
311+ deepnote_big_number_format : 'currency' ,
312+ deepnote_big_number_comparison_enabled : true ,
313+ deepnote_big_number_comparison_type : 'percentage-change' ,
314+ deepnote_big_number_comparison_value : 'last_month_revenue' ,
315+ deepnote_big_number_comparison_title : 'vs last month' ,
316+ deepnote_big_number_comparison_format : 'percent'
317+ } ,
318+ sortingKey : 'a0' ,
319+ type : 'big-number'
320+ } ;
321+
322+ // Convert block to cell (simulating loading from file)
323+ const cell = converter . convertToCell ( originalBlock ) ;
324+
325+ // Manually add metadata like DeepnoteDataConverter does
326+ cell . metadata = {
327+ ...originalBlock . metadata ,
328+ id : originalBlock . id ,
329+ type : originalBlock . type ,
330+ sortingKey : originalBlock . sortingKey ,
331+ blockGroup : originalBlock . blockGroup
332+ } ;
333+
334+ // Move pocket fields
335+ const pocket = {
336+ type : cell . metadata . type ,
337+ sortingKey : cell . metadata . sortingKey ,
338+ blockGroup : cell . metadata . blockGroup
339+ } ;
340+ delete cell . metadata . type ;
341+ delete cell . metadata . sortingKey ;
342+ delete cell . metadata . blockGroup ;
343+ cell . metadata . __deepnotePocket = pocket ;
344+
345+ // Now convert cell back to block (simulating execution)
346+ const reconstructedBlock : DeepnoteBlock = {
347+ blockGroup : pocket . blockGroup || 'default-group' ,
348+ content : cell . value ,
349+ id : cell . metadata . id as string ,
350+ metadata : { ...cell . metadata } ,
351+ sortingKey : pocket . sortingKey || 'a0' ,
352+ type : pocket . type || 'code'
353+ } ;
354+
355+ // Remove pocket and id from metadata
356+ if ( reconstructedBlock . metadata ) {
357+ delete reconstructedBlock . metadata . __deepnotePocket ;
358+ delete reconstructedBlock . metadata . id ;
359+ }
360+
361+ // Apply changes from cell (simulating user editing the value)
362+ converter . applyChangesToBlock ( reconstructedBlock , cell ) ;
363+
364+ // Verify all comparison metadata is preserved
365+ assert . ok ( reconstructedBlock . metadata , 'Block metadata should exist' ) ;
366+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
367+ const metadata = reconstructedBlock . metadata ! ;
368+ assert . strictEqual ( metadata . deepnote_big_number_value , 'revenue' ) ;
369+ assert . strictEqual ( metadata . deepnote_big_number_comparison_enabled , true ) ;
370+ assert . strictEqual ( metadata . deepnote_big_number_comparison_type , 'percentage-change' ) ;
371+ assert . strictEqual ( metadata . deepnote_big_number_comparison_value , 'last_month_revenue' ) ;
372+ assert . strictEqual ( metadata . deepnote_big_number_comparison_title , 'vs last month' ) ;
373+ assert . strictEqual ( metadata . deepnote_big_number_comparison_format , 'percent' ) ;
374+ } ) ;
375+
270376 test ( 'handles empty content' , ( ) => {
271377 const block : DeepnoteBlock = {
272378 blockGroup : 'test-group' ,
0 commit comments