2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # cindex --join functionality against mwrap, a small projects
5 # started as C+Ruby and got forked to C+Perl/XS w/ public inboxes for each
7 use PublicInbox::TestCommon;
8 use PublicInbox::IO qw(write_file);
9 use PublicInbox::Import;
10 use PublicInbox::Config;
13 $ENV{TEST_REMOTE_JOIN} or plan skip_all => 'TEST_REMOTE_JOIN unset';
15 local $ENV{TAIL_ALL} = $ENV{TAIL_ALL} // 1; # while features are unstable
16 require_mods(qw(json Xapian DBD::SQLite +SCM_RIGHTS));
17 my @code = qw(https://80x24.org/mwrap-perl.git
18 https://80x24.org/mwrap.git);
19 my @inboxes = qw(https://80x24.org/mwrap-public 2 inbox.comp.lang.ruby.mwrap
20 https://80x24.org/mwrap-perl 2 inbox.comp.lang.perl.mwrap);
22 my $topdir = File::Spec->rel2abs('.');
24 while (my $url = shift @code) {
25 my ($key) = ($url =~ m!/([^/]+\.git)\z!);
26 $code{$key} = create_coderepo $key, sub {
27 PublicInbox::Import::init_bare '.';
28 write_file '>>', 'config', <<EOM;
31 fetch = +refs/*:refs/*
34 if (my $d = $code{'mwrap-perl.git'}) {
35 $d = File::Spec->abs2rel("$topdir/$d", 'objects');
36 write_file '>','objects/info/alternates',"$d/objects\n"
38 diag "mirroring coderepo: $url ...";
39 xsys_e qw(git fetch -q origin);
43 while (my ($url, $v, $ng) = splice(@inboxes, 0, 3)) {
44 my ($key) = ($url =~ m!/([^/]+)\z!);
45 my @opt = (version => $v, tmpdir => "$tmpdir/$key", -no_gc => 1);
46 $inboxes{$key} = create_inbox $key, @opt, sub {
49 diag "cloning public-inbox $url ...";
50 run_script([qw(-clone -q), $url, $ibx->{inboxdir}]) or
52 diag "indexing $ibx->{inboxdir} ...";
53 run_script([qw(-index -v -L medium --dangerous),
54 $ibx->{inboxdir}]) or xbail "index: $?";
56 $inboxes{$key}->{newsgroup} = $ng;
59 open my $fh, '>', $env->{PI_CONFIG} = "$tmpdir/pi_config";
60 for (sort keys %inboxes) {
63 inboxdir = $inboxes{$_}->{inboxdir}
64 address = $_\@80x24.org
65 newsgroup = $inboxes{$_}->{newsgroup}
69 my $cidxdir = "$tmpdir/cidx";
70 # this should be fast since mwrap* are small
71 my $rdr = { 1 => \my $cout, 2 => \my $cerr };
72 ok run_script([qw(-cindex -v --all --show=join_data),
73 '--join=aggressive,dt:..2022-12-01',
74 '-d', $cidxdir, map { ('-g', $_) } values %code ],
75 $env, $rdr), 'initial join inboxes w/ coderepos';
76 my $out = PublicInbox::Config->json->decode($cout);
77 is($out->{join_data}->{dt}->[0], '19700101'.'000000',
78 'dt:..$END_DATE starts from epoch');
80 ok run_script([qw(-cindex -v --all -u --join --show),
81 '-d', $cidxdir], $env, $rdr), 'incremental --join';
83 ok run_script([qw(-cindex -v --no-scan --show),
84 '-d', $cidxdir], $env, $rdr), 'show';
85 $out = PublicInbox::Config->json->decode($cout);
86 is ref($out->{join_data}), 'HASH', 'got hash join data';
87 is $cerr, '', 'no warnings or errors in stderr w/ --show';