innodb-utils 5.1.0

InnoDB file analysis toolkit
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
#![cfg(feature = "cli")]
//! Integration tests for `inno verify`.

use byteorder::{BigEndian, ByteOrder};
use std::io::Write;
use tempfile::NamedTempFile;

use idb::innodb::checksum::{recalculate_checksum, ChecksumAlgorithm};
use idb::innodb::constants::*;
use idb::innodb::write;

const PAGE_SIZE: u32 = 16384;
const PS: usize = PAGE_SIZE as usize;

fn build_fsp_hdr_page(space_id: u32, total_pages: u32) -> Vec<u8> {
    write::build_fsp_page(
        space_id,
        total_pages,
        0,
        1000,
        PAGE_SIZE,
        ChecksumAlgorithm::Crc32c,
    )
}

fn build_index_page(page_num: u32, space_id: u32, lsn: u64, prev: u32, next: u32) -> Vec<u8> {
    let mut page = vec![0u8; PS];

    // FIL header
    BigEndian::write_u32(&mut page[FIL_PAGE_OFFSET..], page_num);
    BigEndian::write_u32(&mut page[FIL_PAGE_PREV..], prev);
    BigEndian::write_u32(&mut page[FIL_PAGE_NEXT..], next);
    BigEndian::write_u64(&mut page[FIL_PAGE_LSN..], lsn);
    BigEndian::write_u16(&mut page[FIL_PAGE_TYPE..], 17855); // INDEX
    BigEndian::write_u32(&mut page[FIL_PAGE_SPACE_ID..], space_id);

    // INDEX page header (minimal)
    let ph = FIL_PAGE_DATA;
    BigEndian::write_u16(&mut page[ph + PAGE_N_DIR_SLOTS..], 2);
    BigEndian::write_u16(&mut page[ph + PAGE_HEAP_TOP..], 200);
    BigEndian::write_u16(&mut page[ph + PAGE_N_HEAP..], 0x8002); // compact
    BigEndian::write_u16(&mut page[ph + PAGE_N_RECS..], 1);
    BigEndian::write_u16(&mut page[ph + PAGE_LEVEL..], 0); // leaf
    BigEndian::write_u64(&mut page[ph + PAGE_INDEX_ID..], 100);

    // FIL trailer
    let trailer = PS - SIZE_FIL_TRAILER;
    BigEndian::write_u32(&mut page[trailer + 4..], (lsn & 0xFFFFFFFF) as u32);

    recalculate_checksum(&mut page, PAGE_SIZE, ChecksumAlgorithm::Crc32c);
    page
}

fn write_tablespace(pages: &[Vec<u8>]) -> NamedTempFile {
    let mut tmp = NamedTempFile::new().unwrap();
    for page in pages {
        tmp.write_all(page).unwrap();
    }
    tmp.flush().unwrap();
    tmp
}

// ── Test: valid tablespace passes all checks ─────────────────────────

#[test]
fn test_verify_passes_valid_tablespace() {
    let page0 = build_fsp_hdr_page(42, 4);
    let page1 = build_index_page(1, 42, 2000, FIL_NULL, 2);
    let page2 = build_index_page(2, 42, 3000, 1, FIL_NULL);
    let page3 = build_index_page(3, 42, 4000, FIL_NULL, FIL_NULL);

    let tmp = write_tablespace(&[page0, page1, page2, page3]);
    let path = tmp.path().to_str().unwrap();

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: path.to_string(),
            verbose: false,
            json: false,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(
        result.is_ok(),
        "Expected verify to pass on valid tablespace"
    );
    let text = String::from_utf8(output).unwrap();
    assert!(text.contains("PASS"));
    assert!(text.contains("Structural Verification"));
}

// ── Test: wrong page_number in header fails PageNumberSequence ───────

#[test]
fn test_verify_fails_wrong_page_number() {
    let page0 = build_fsp_hdr_page(42, 3);

    // Build page at position 1 but with page_number 5 in header
    let mut page1 = build_index_page(5, 42, 2000, FIL_NULL, FIL_NULL);
    // page_number is already set to 5 by build_index_page
    recalculate_checksum(&mut page1, PAGE_SIZE, ChecksumAlgorithm::Crc32c);

    let page2 = build_index_page(2, 42, 3000, FIL_NULL, FIL_NULL);

    let tmp = write_tablespace(&[page0, page1, page2]);
    let path = tmp.path().to_str().unwrap();

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: path.to_string(),
            verbose: true,
            json: false,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(
        result.is_err(),
        "Expected verify to fail on wrong page number"
    );
    let text = String::from_utf8(output).unwrap();
    assert!(text.contains("FAIL"));
    assert!(text.contains("page_number_sequence"));
    assert!(text.contains("Page 1 has page_number 5"));
}

// ── Test: mixed space_ids fails SpaceIdConsistency ───────────────────

#[test]
fn test_verify_fails_mixed_space_ids() {
    let page0 = build_fsp_hdr_page(42, 3);

    // Build page 1 with space_id 99 instead of 42
    let page1 = build_index_page(1, 99, 2000, FIL_NULL, FIL_NULL);
    let page2 = build_index_page(2, 42, 3000, FIL_NULL, FIL_NULL);

    let tmp = write_tablespace(&[page0, page1, page2]);
    let path = tmp.path().to_str().unwrap();

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: path.to_string(),
            verbose: true,
            json: false,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(
        result.is_err(),
        "Expected verify to fail on mixed space IDs"
    );
    let text = String::from_utf8(output).unwrap();
    assert!(text.contains("space_id_consistency"));
    assert!(text.contains("space_id 99"));
}

// ── Test: broken prev/next chain fails PageChainBounds ──────────────

#[test]
fn test_verify_fails_chain_out_of_bounds() {
    let page0 = build_fsp_hdr_page(42, 3);

    // Build page 1 with next pointer pointing beyond file bounds
    let page1 = build_index_page(1, 42, 2000, FIL_NULL, 999);
    let page2 = build_index_page(2, 42, 3000, FIL_NULL, FIL_NULL);

    let tmp = write_tablespace(&[page0, page1, page2]);
    let path = tmp.path().to_str().unwrap();

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: path.to_string(),
            verbose: true,
            json: false,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(
        result.is_err(),
        "Expected verify to fail on out-of-bounds chain pointer"
    );
    let text = String::from_utf8(output).unwrap();
    assert!(text.contains("page_chain_bounds"));
    assert!(text.contains("next pointer 999"));
}

// ── Test: trailer LSN mismatch fails TrailerLsnMatch ────────────────

#[test]
fn test_verify_fails_trailer_lsn_mismatch() {
    let page0 = build_fsp_hdr_page(42, 2);

    // Build page 1 with correct header LSN but broken trailer
    let mut page1 = vec![0u8; PS];
    let lsn: u64 = 5000;
    BigEndian::write_u32(&mut page1[FIL_PAGE_OFFSET..], 1);
    BigEndian::write_u32(&mut page1[FIL_PAGE_PREV..], FIL_NULL);
    BigEndian::write_u32(&mut page1[FIL_PAGE_NEXT..], FIL_NULL);
    BigEndian::write_u64(&mut page1[FIL_PAGE_LSN..], lsn);
    BigEndian::write_u16(&mut page1[FIL_PAGE_TYPE..], 17855);
    BigEndian::write_u32(&mut page1[FIL_PAGE_SPACE_ID..], 42);

    // Set trailer LSN low-32 to a WRONG value
    let trailer = PS - SIZE_FIL_TRAILER;
    BigEndian::write_u32(&mut page1[trailer + 4..], 0xDEADBEEF);

    // Recalculate checksum (checksum won't fix the trailer LSN mismatch)
    recalculate_checksum(&mut page1, PAGE_SIZE, ChecksumAlgorithm::Crc32c);

    let tmp = write_tablespace(&[page0, page1]);
    let path = tmp.path().to_str().unwrap();

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: path.to_string(),
            verbose: true,
            json: false,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(
        result.is_err(),
        "Expected verify to fail on trailer LSN mismatch"
    );
    let text = String::from_utf8(output).unwrap();
    assert!(text.contains("trailer_lsn_match"));
}

// ── Test: JSON output is valid and contains expected fields ─────────

#[test]
fn test_verify_json_output_valid_tablespace() {
    let page0 = build_fsp_hdr_page(42, 3);
    let page1 = build_index_page(1, 42, 2000, FIL_NULL, FIL_NULL);
    let page2 = build_index_page(2, 42, 3000, FIL_NULL, FIL_NULL);

    let tmp = write_tablespace(&[page0, page1, page2]);
    let path = tmp.path().to_str().unwrap();

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: path.to_string(),
            verbose: false,
            json: true,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(result.is_ok());

    let json: serde_json::Value = serde_json::from_slice(&output).unwrap();
    assert!(json.get("file").is_some());
    assert_eq!(json["total_pages"], 3);
    assert_eq!(json["page_size"], 16384);
    assert_eq!(json["passed"], true);
    // findings is omitted from JSON when empty (skip_serializing_if)
    assert!(json.get("findings").is_none());
    assert!(!json["summary"].as_array().unwrap().is_empty());

    // Check that all summary entries have the expected fields
    for s in json["summary"].as_array().unwrap() {
        assert!(s.get("kind").is_some());
        assert!(s.get("pages_checked").is_some());
        assert!(s.get("issues_found").is_some());
        assert!(s.get("passed").is_some());
    }
}

// ── Test: JSON output with failures includes findings ───────────────

#[test]
fn test_verify_json_output_with_failures() {
    let page0 = build_fsp_hdr_page(42, 2);

    // Build page 1 with wrong space_id
    let page1 = build_index_page(1, 99, 2000, FIL_NULL, FIL_NULL);

    let tmp = write_tablespace(&[page0, page1]);
    let path = tmp.path().to_str().unwrap();

    let mut output = Vec::new();
    let _result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: path.to_string(),
            verbose: false,
            json: true,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: None,
        },
        &mut output,
    );

    let json: serde_json::Value = serde_json::from_slice(&output).unwrap();
    assert_eq!(json["passed"], false);
    assert!(!json["findings"].as_array().unwrap().is_empty());

    // Check that at least one finding has the space_id issue
    let findings = json["findings"].as_array().unwrap();
    let has_space_id_finding = findings.iter().any(|f| f["kind"] == "SpaceIdConsistency");
    assert!(
        has_space_id_finding,
        "Expected to find SpaceIdConsistency finding in JSON"
    );

    // Check that the summary for space_id_consistency shows failure
    let summaries = json["summary"].as_array().unwrap();
    let space_id_summary = summaries
        .iter()
        .find(|s| s["kind"] == "SpaceIdConsistency")
        .unwrap();
    assert_eq!(space_id_summary["passed"], false);
    assert!(space_id_summary["issues_found"].as_u64().unwrap() > 0);
}

// ── Test: valid tablespace with empty pages passes ──────────────────

#[test]
fn test_verify_passes_with_empty_pages() {
    let page0 = build_fsp_hdr_page(42, 3);
    let page1 = vec![0u8; PS]; // all-zero page (should be skipped)
    let page2 = build_index_page(2, 42, 3000, FIL_NULL, FIL_NULL);

    let tmp = write_tablespace(&[page0, page1, page2]);
    let path = tmp.path().to_str().unwrap();

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: path.to_string(),
            verbose: false,
            json: false,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(
        result.is_ok(),
        "Expected verify to pass when empty pages are present"
    );
}

// ── Test: prev pointer out of bounds ────────────────────────────────

#[test]
fn test_verify_fails_prev_pointer_out_of_bounds() {
    let page0 = build_fsp_hdr_page(42, 2);

    // Build page 1 with prev pointing beyond file
    let page1 = build_index_page(1, 42, 2000, 500, FIL_NULL);

    let tmp = write_tablespace(&[page0, page1]);
    let path = tmp.path().to_str().unwrap();

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: path.to_string(),
            verbose: true,
            json: false,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(
        result.is_err(),
        "Expected verify to fail on prev pointer out of bounds"
    );
    let text = String::from_utf8(output).unwrap();
    assert!(text.contains("prev pointer 500"));
}

// ── Backup chain tests ──────────────────────────────────────────────

#[test]
fn test_chain_contiguous_passes() {
    // Two tablespaces with overlapping LSN ranges
    let page0a = build_fsp_hdr_page(42, 2);
    let page1a = build_index_page(1, 42, 1000, FIL_NULL, FIL_NULL);
    let file_a = write_tablespace(&[page0a, page1a]);

    let page0b = build_fsp_hdr_page(42, 2);
    let page1b = build_index_page(1, 42, 2000, FIL_NULL, FIL_NULL);
    let file_b = write_tablespace(&[page0b, page1b]);

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: file_a.path().to_str().unwrap().to_string(),
            verbose: false,
            json: false,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![
                file_a.path().to_str().unwrap().to_string(),
                file_b.path().to_str().unwrap().to_string(),
            ],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(result.is_ok(), "Expected chain to pass");
    let text = String::from_utf8(output).unwrap();
    assert!(text.contains("PASS"));
}

#[test]
fn test_chain_json_output() {
    let page0a = build_fsp_hdr_page(42, 2);
    let page1a = build_index_page(1, 42, 1000, FIL_NULL, FIL_NULL);
    let file_a = write_tablespace(&[page0a, page1a]);

    let page0b = build_fsp_hdr_page(42, 2);
    let page1b = build_index_page(1, 42, 2000, FIL_NULL, FIL_NULL);
    let file_b = write_tablespace(&[page0b, page1b]);

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: file_a.path().to_str().unwrap().to_string(),
            verbose: false,
            json: true,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![
                file_a.path().to_str().unwrap().to_string(),
                file_b.path().to_str().unwrap().to_string(),
            ],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(result.is_ok());
    let text = String::from_utf8(output).unwrap();
    let json: serde_json::Value = serde_json::from_str(&text).unwrap();
    assert_eq!(json["contiguous"], true);
    assert_eq!(json["consistent_space_id"], true);
    assert_eq!(json["files"].as_array().unwrap().len(), 2);
}

#[test]
fn test_chain_mixed_space_ids_fails() {
    let page0a = build_fsp_hdr_page(42, 2);
    let page1a = build_index_page(1, 42, 1000, FIL_NULL, FIL_NULL);
    let file_a = write_tablespace(&[page0a, page1a]);

    // Different space_id
    let page0b = build_fsp_hdr_page(99, 2);
    let page1b = build_index_page(1, 99, 2000, FIL_NULL, FIL_NULL);
    let file_b = write_tablespace(&[page0b, page1b]);

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: file_a.path().to_str().unwrap().to_string(),
            verbose: false,
            json: false,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![
                file_a.path().to_str().unwrap().to_string(),
                file_b.path().to_str().unwrap().to_string(),
            ],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(
        result.is_err(),
        "Expected chain to fail with mixed space IDs"
    );
    let text = String::from_utf8(output).unwrap();
    assert!(text.contains("FAIL"));
}

#[test]
fn test_chain_requires_two_files() {
    let page0 = build_fsp_hdr_page(42, 2);
    let page1 = build_index_page(1, 42, 1000, FIL_NULL, FIL_NULL);
    let file_a = write_tablespace(&[page0, page1]);

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: file_a.path().to_str().unwrap().to_string(),
            verbose: false,
            json: false,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![file_a.path().to_str().unwrap().to_string()],
            backup_meta: None,
        },
        &mut output,
    );

    assert!(result.is_err());
}

// ── Backup metadata tests ─────────────────────────────────────────────

#[test]
fn test_verify_backup_meta_within_window() {
    use std::io::Write as IoWrite;

    let page0 = build_fsp_hdr_page(42, 3);
    let page1 = build_index_page(1, 42, 2000, FIL_NULL, FIL_NULL);
    let page2 = build_index_page(2, 42, 3000, FIL_NULL, FIL_NULL);

    let ts_file = write_tablespace(&[page0, page1, page2]);

    // Create checkpoint file with LSN window covering the tablespace
    let mut ckpt = tempfile::NamedTempFile::new().unwrap();
    writeln!(ckpt, "backup_type = full-backuped").unwrap();
    writeln!(ckpt, "from_lsn = 0").unwrap();
    writeln!(ckpt, "to_lsn = 5000").unwrap();
    writeln!(ckpt, "last_lsn = 5000").unwrap();
    ckpt.flush().unwrap();

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: ts_file.path().to_str().unwrap().to_string(),
            verbose: false,
            json: true,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: Some(ckpt.path().to_str().unwrap().to_string()),
        },
        &mut output,
    );

    assert!(
        result.is_ok(),
        "Expected verify to pass when LSNs within window"
    );

    let json: serde_json::Value = serde_json::from_slice(&output).unwrap();
    let meta = &json["backup_meta"];
    assert_eq!(meta["passed"], true);
    assert_eq!(meta["from_lsn"], 0);
    assert_eq!(meta["to_lsn"], 5000);
    assert!(meta["pages_before_window"].as_array().unwrap().is_empty());
    assert!(meta["pages_after_window"].as_array().unwrap().is_empty());
}

#[test]
fn test_verify_backup_meta_pages_outside_window() {
    use std::io::Write as IoWrite;

    let page0 = build_fsp_hdr_page(42, 3);
    let page1 = build_index_page(1, 42, 2000, FIL_NULL, FIL_NULL);
    // Page 2 has LSN 9000 which is beyond to_lsn of 5000
    let page2 = build_index_page(2, 42, 9000, FIL_NULL, FIL_NULL);

    let ts_file = write_tablespace(&[page0, page1, page2]);

    // Create checkpoint file with tight LSN window
    let mut ckpt = tempfile::NamedTempFile::new().unwrap();
    writeln!(ckpt, "backup_type = full-backuped").unwrap();
    writeln!(ckpt, "from_lsn = 1500").unwrap();
    writeln!(ckpt, "to_lsn = 5000").unwrap();
    writeln!(ckpt, "last_lsn = 5000").unwrap();
    ckpt.flush().unwrap();

    let mut output = Vec::new();
    let result = idb::cli::verify::execute(
        &idb::cli::verify::VerifyOptions {
            file: ts_file.path().to_str().unwrap().to_string(),
            verbose: true,
            json: true,
            page_size: None,
            keyring: None,
            mmap: false,
            redo: None,
            chain: vec![],
            backup_meta: Some(ckpt.path().to_str().unwrap().to_string()),
        },
        &mut output,
    );

    // Verify should fail because page 2 LSN exceeds to_lsn
    assert!(
        result.is_err(),
        "Expected verify to fail with pages outside window"
    );

    let json: serde_json::Value = serde_json::from_slice(&output).unwrap();
    let meta = &json["backup_meta"];
    assert_eq!(meta["passed"], false);
    assert!(!meta["pages_after_window"].as_array().unwrap().is_empty());

    // Check that page 2 is in the after-window list
    let after = meta["pages_after_window"].as_array().unwrap();
    let page2_issue = after.iter().find(|p| p["page_number"] == 2);
    assert!(
        page2_issue.is_some(),
        "Expected page 2 in pages_after_window"
    );
    assert_eq!(page2_issue.unwrap()["lsn"], 9000);
}