+
+ my %lg;
+ foreach my $num (@{$n->listgroup($group)}) {
+ is($lg{$num}++, 0, "num is unique in LISTGROUP");
+ }
+ is_deeply([sort keys %lg], [sort keys %$x],
+ 'XOVER and LISTGROUPS return the same article numbers');
+
+ my $xref = $n->xhdr('Xref', '1-');
+ is_deeply([sort keys %lg], [sort keys %$xref], 'Xref range OK');
+
+ my $mids = $n->xhdr('Message-ID', '1-');
+ is_deeply([sort keys %lg], [sort keys %$xref], 'Message-ID range OK');
+
+ my $rover = $n->xrover('1-');
+ is_deeply([sort keys %lg], [sort keys %$rover], 'XROVER range OK');
+};
+{
+ my @log = qw(log --no-decorate --no-abbrev --no-notes --no-color);
+ my @before = $git0->qx(@log, qw(--pretty=oneline));
+ my $before = $git0->qx(@log, qw(--pretty=raw --raw -r));
+ $im = PublicInbox::V2Writable->new($ibx, {nproc => 2});
+ is($im->{shards}, 1, 'detected single shard from previous');
+ my ($mark, $rm_mime, $smsg) = $im->remove($mime, 'test removal');
+ is(content_hash($rm_mime), content_hash($mime),
+ 'removed object returned matches');
+ ok(defined($mark), 'mark set');
+ $im->done;
+ my @after = $git0->qx(@log, qw(--pretty=oneline));
+ my $tip = shift @after;
+ like($tip, qr/\A[a-f0-9]+ test removal\n\z/s,
+ 'commit message propagated to git');
+ is_deeply(\@after, \@before, 'only one commit written to git');
+ my $mid = $smsg->{mid};
+ is($ibx->mm->num_for($mid), undef, 'no longer in Msgmap by mid');
+ my $num = $smsg->{num};
+ like($num, qr/\A\d+\z/, 'numeric number in return message');
+ is($ibx->mm->mid_for($num), undef, 'no longer in Msgmap by num');
+ my $mset = $ibx->search->reopen->mset('m:'.$mid);
+ is($mset->size, 0, 'no longer found in Xapian');
+ my @log1 = (@log, qw(-1 --pretty=raw --raw -r --no-renames));
+ is($ibx->over->get_art($num), undef,
+ 'removal propagated to Over DB');
+
+ my $after = $git0->qx(@log1);
+ if ($after =~ m!( [a-f0-9]+ )A\td$!m) {
+ my $oid = $1;
+ ok(index($before, $oid) > 0, 'no new blob introduced');
+ } else {
+ fail('failed to extract blob from log output');
+ }
+ is($im->remove($mime, 'test removal'), undef,
+ 'remove is idempotent');
+ $im->done;
+ is($git0->qx(@log1),
+ $after, 'no git history made with idempotent remove');
+ eval { $im->done };
+ ok(!$@, '->done is idempotent');
+}
+
+{
+ ok($im->add($mime), 'add message to be purged');
+ local $SIG{__WARN__} = sub {};
+ ok(my $cmt = $im->purge($mime), 'purged message');
+ like($cmt->[0], qr/\A[a-f0-9]{40,}\z/, 'purge returned current commit');
+ $im->done;
+
+ # again
+ is($im->purge($mime), undef, 'no-op returns undef');
+}
+
+{
+ my $x = 'x'x250;
+ my $y = 'y'x250;
+ local $SIG{__WARN__} = sub {};
+ $mime->header_set('Subject', 'long mid');
+ $mime->header_set('Message-ID', "<$x>");
+ ok($im->add($mime), 'add excessively long Message-ID');
+
+ $mime->header_set('Message-ID', "<$y>");
+ $mime->header_set('References', "<$x>");
+ ok($im->add($mime), 'add excessively long References');
+ $im->done;
+
+ my $msgs = $ibx->over->get_thread('x'x244);
+ is(2, scalar(@$msgs), 'got both messages');
+ is($msgs->[0]->{mid}, 'x'x244, 'stored truncated mid');
+ is($msgs->[1]->{references}, '<'.('x'x244).'>', 'stored truncated ref');
+ is($msgs->[1]->{mid}, 'y'x244, 'stored truncated mid(2)');
+}
+
+if ('UTF-8 References') {
+ my @w;
+ local $SIG{__WARN__} = sub { push @w, @_ };
+ my $msg = <<EOM;
+From: a\@example.com
+Subject: b
+Message-ID: <horrible\@example>
+References: <\xc4\x80\@example>
+
+EOM
+ ok($im->add(PublicInbox::Eml->new($msg."a\n")), 'UTF-8 References 1');
+ ok($im->add(PublicInbox::Eml->new($msg."b\n")), 'UTF-8 References 2');
+ $im->done;
+ ok(!grep(/Wide character/, @w), 'no wide characters') or xbail(\@w);
+}
+
+my $tmp = {
+ inboxdir => "$inboxdir/non-existent/subdir",
+ name => 'nope',
+ version => 2,
+ -primary_address => 'test@example.com',