From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6DEDD1F406 for ; Sun, 15 Oct 2023 08:16:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1697357788; bh=Njpt6n1G2iPHJ55gFMed9E5bADchpQXADY6HhwZeDyk=; h=From:To:Subject:Date:From; b=dx3OLtATKagDzdtkcam4INV/TUEPNmUuc5iVZvwP5/Sba5nYwa4jIDUI07FArpSLm SAG+pqqFVLKkqDgl30OlSXI511zE06vZ77q639TT6ekjIDs4dFLzsko3NFLQYUfYAT aTWxPjd/fdMKtzKQN5dPzPbLdX0c4I6c2+HHXM+E= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] learn: respect indexlevel for v1 inboxes Date: Sun, 15 Oct 2023 08:16:28 +0000 Message-ID: <20231015081628.956814-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: v2 never suffered from this bug, apparently, but -learn didn't seem able to handle indexlevel=basic (nor respect `medium') for v1 inboxes. I only noticed this bug because I converted some ancient v1 inboxes to `basic' to save space. --- script/public-inbox-learn | 1 + t/mda.t | 37 ++++++++++++++++++++++++++++++++++++- t/v2mda.t | 27 ++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/script/public-inbox-learn b/script/public-inbox-learn index 6e1978a7..54d31cb6 100755 --- a/script/public-inbox-learn +++ b/script/public-inbox-learn @@ -64,6 +64,7 @@ sub remove_or_add ($$$$) { $ibx->{name} = $ENV{GIT_COMMITTER_NAME} // $ibx->{name}; $ibx->{-primary_address} = $ENV{GIT_COMMITTER_EMAIL} // $addr; $ibx = PublicInbox::InboxWritable->new($ibx); + $ibx->{indexlevel} = $ibx->detect_indexlevel; my $im = $ibx->importer(0); if ($train eq "rm") { diff --git a/t/mda.t b/t/mda.t index e3c5cdff..83b0b33a 100644 --- a/t/mda.t +++ b/t/mda.t @@ -2,13 +2,13 @@ # License: AGPL-3.0+ use strict; use warnings; -use Test::More; use Cwd qw(getcwd); use PublicInbox::MID qw(mid2path); use PublicInbox::Git; use PublicInbox::InboxWritable; use PublicInbox::TestCommon; use PublicInbox::Import; +use File::Path qw(remove_tree); my ($tmpdir, $for_destroy) = tmpdir(); my $home = "$tmpdir/pi-home"; my $pi_home = "$home/.public-inbox"; @@ -312,4 +312,39 @@ EOF like($cur, qr/^-Message-ID: <2lids\@example>/sm, 'changed in git'); } +SKIP: { + require_mods(qw(DBD::SQLite Xapian), 1); + local $ENV{PI_EMERGENCY} = $faildir; + local $ENV{HOME} = $home; + local $ENV{PATH} = $main_path; + my $rdr = { 1 => \(my $out = ''), 2 => \(my $err = '') }; + ok(run_script([qw(-index -L medium), $maindir], undef, $rdr), + 'index inbox'); + my $in = <<'EOM'; +From: a@example.com +To: updated-address@example.com +Subject: this is a ham message for learn +Date: Fri, 02 Oct 1993 00:00:00 +0000 +Message-ID: + +yum +EOM + $rdr->{0} = \$in; + ok(run_script([qw(-learn ham)], undef, $rdr), 'learn medium ham'); + is($err, '', 'nothing in stderr after medium -learn'); + my $msg = $git->cat_file('HEAD:'.mid2path('medium-ham@example')); + like($$msg, qr/medium-ham/, 'medium ham added via -learn'); + my @xap = grep(!m!/over\.sqlite3!, + glob("$maindir/public-inbox/xapian*/*")); + ok(remove_tree(@xap), 'rm Xapian files to convert to indexlevel=basic'); + $in =~ s/medium-ham/basic-ham/g or xbail 'BUG: no s//'; + ok(run_script([qw(-learn ham)], undef, $rdr), 'learn basic ham'); + is($err, '', 'nothing in stderr after basic -learn'); + $msg = $git->cat_file('HEAD:'.mid2path('basic-ham@example')); + like($$msg, qr/basic-ham/, 'basic ham added via -learn'); + @xap = grep(!m!/over\.sqlite3!, + glob("$maindir/public-inbox/xapian*/*")); + is_deeply(\@xap, [], 'no Xapian files created by -learn'); +}; + done_testing(); diff --git a/t/v2mda.t b/t/v2mda.t index a49eeb6d..b7d177b2 100644 --- a/t/v2mda.t +++ b/t/v2mda.t @@ -3,11 +3,11 @@ # License: AGPL-3.0+ use v5.10.1; use strict; -use Test::More; use Fcntl qw(SEEK_SET); use Cwd; use PublicInbox::TestCommon; use PublicInbox::Eml; +use File::Path qw(remove_tree); require_git(2.6); my $V = 2; @@ -96,4 +96,29 @@ is($eml->as_string, $mime->as_string, 'injected message'); is($mset->size, 1, 'patchid search works'); } +{ + my @shards = grep(m!/[0-9]+\z!, glob("$ibx->{inboxdir}/xap*/*")); + ok(remove_tree(@shards), 'rm shards to convert to indexlevel=basic'); + $ibx->do_cleanup; + $rdr->{2} = \(my $err = ''); + $rdr->{0} = \<<'EOM'; +From: a@example.com +To: test@example.com +Subject: this is a ham message for learn +Date: Fri, 02 Oct 1993 00:00:00 +0000 +Message-ID: + +yum +EOM + my ($id, $prev); + is($ibx->over->next_by_mid('ham@example', \$id, \$prev), undef, + 'no ham@example, yet'); + ok(run_script([qw(-learn ham)], undef, $rdr), '-learn runs on basic') + or diag $err; + my $smsg = $ibx->over->next_by_mid('ham@example', \$id, \$prev); + ok($smsg, 'ham message learned w/ indexlevel=basic'); + @shards = grep(m!/[0-9]+\z!, glob("$ibx->{inboxdir}/xap*/*")); + is_deeply(\@shards, [], 'not converted to medium/full after learn'); +} + done_testing();