+
+ my $f = "$ENV{HOME}/.local/share/lei/store/mail_sync.sqlite3";
+ ok(-s $f, 'mail_sync exists tracked for redundant imports');
+ lei_ok 'ls-mail-sync';
+ like($lei_out, qr!\A\Q$url\E\n\z!, 'ls-mail-sync output as-expected');
+
+ ok(!lei(qw(import), "$url/12-1"), 'backwards range rejected');
+
+ # new home
+ local $ENV{HOME} = "$tmpdir/h2";
+ lei_ok(qw(ls-mail-source -l), $url);
+ my $ls = json_utf8->decode($lei_out);
+ my ($high, $low) = @{$ls->[0]}{qw(high low)};
+ ok($high > $low, 'high > low');
+
+ my $end = $high - 1;
+ lei_ok qw(import), "$url/$high";
+ lei_ok('inspect', $url); is_xdeeply(json_utf8->decode($lei_out), {
+ $url => { 'article.count' => 1,
+ 'article.min' => $high,
+ 'article.max' => $high, }
+ }, 'inspect output for URL after single message') or diag $lei_out;
+ lei_ok('inspect', "$url/$high");
+ my $x = json_utf8->decode($lei_out);
+ like($x->{$url}->{$high}, qr/\A[a-f0-9]{40,}\z/, 'inspect shows blob');
+ lei_ok qw(lcat -f json), "$url/$high";
+ my $lcat = json_utf8->decode($lei_out);
+ is($lcat->[1], undef, 'only one result for lcat');
+ is($lcat->[0]->{blob}, $x->{$url}->{$high},
+ 'lcat showed correct blob');
+
+ lei_ok 'ls-mail-sync';
+ is($lei_out, "$url\n", 'article number not stored as folder');
+ lei_ok qw(q z:0..); my $one = json_utf8->decode($lei_out);
+ pop @$one; # trailing null
+ is(scalar(@$one), 1, 'only 1 result');
+
+ local $ENV{HOME} = "$tmpdir/h3";
+ lei_ok qw(import), "$url/$low-$end";
+ lei_ok('inspect', $url); is_xdeeply(json_utf8->decode($lei_out), {
+ $url => { 'article.count' => $end - $low + 1,
+ 'article.min' => $low,
+ 'article.max' => $end, }
+ }, 'inspect output for URL after range') or diag $lei_out;
+ lei_ok('inspect', "$url/$low-$end");
+ $x = json_utf8->decode($lei_out);
+ is_deeply([ ($low..$end) ], [ sort { $a <=> $b } keys %{$x->{$url}} ],
+ 'inspect range shows range');
+ is(scalar(grep(/\A[a-f0-9]{40,}\z/, values %{$x->{$url}})),
+ $end - $low + 1, 'all values are git blobs');
+
+ lei_ok qw(lcat -f json), "$url/$low";
+ $lcat = json_utf8->decode($lei_out);
+ is($lcat->[1], undef, 'only one result for lcat');
+ is($lcat->[0]->{blob}, $x->{$url}->{$low},
+ 'lcat showed correct blob');
+ lei_ok qw(lcat -f json), "$url/$low-$end";
+ $lcat = json_utf8->decode($lei_out);
+ pop @$lcat;
+ for ($low..$end) {
+ my $tip = shift @$lcat;
+ is($x->{$url}->{$_}, $tip->{blob}, "blob matches art #$_");
+ }
+
+ lei_ok 'ls-mail-sync';
+ is($lei_out, "$url\n", 'article range not stored as folder');
+ lei_ok qw(q z:0..); my $start = json_utf8->decode($lei_out);
+ pop @$start; # trailing null
+ is(scalar(@$start), scalar(map { $_ } ($low..$end)),
+ 'range worked as expected');
+ my %seen;
+ for (@$start, @$one) {
+ is($seen{$_->{blob}}++, 0, "blob $_->{blob} seen once");
+ }