perlsky is a Perl 5 implementation of an AT Protocol Personal Data Server.
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

Strengthen repo export and firehose tests

alice d4e42d78 219703b1

+16 -7
+4 -4
t/firehose.t
··· 124 124 'initial firehose CAR includes the created record block', 125 125 ); 126 126 my $initial_commit = decode_dag_cbor($initial_commit_block->{bytes}); 127 - ok(exists $initial_commit->{prev}, 'initial commit includes prev for compatibility'); 128 - ok(!defined $initial_commit->{prev}, 'initial commit prev is null'); 127 + is($initial_commit->{did}, $did, 'initial commit block belongs to the repo'); 128 + is($initial_commit->{rev}, $decoded->{body}{rev}, 'initial commit block rev matches the event'); 129 129 130 130 my $initial_rev = $decoded->{body}{rev}; 131 131 ··· 175 175 'second firehose CAR does not resend unchanged prior record blocks', 176 176 ); 177 177 my $second_commit = decode_dag_cbor($second_commit_block->{bytes}); 178 - ok(exists $second_commit->{prev}, 'subsequent commit includes prev for compatibility'); 179 - ok(!defined $second_commit->{prev}, 'subsequent commit prev is null'); 178 + is($second_commit->{did}, $did, 'subsequent commit block belongs to the repo'); 179 + is($second_commit->{rev}, $second->{body}{rev}, 'subsequent commit block rev matches the event'); 180 180 $follow->finish_ok; 181 181 182 182 my $future = Test::Mojo->new($app);
+3 -2
t/import-repo.t
··· 98 98 99 99 my $records = $t->tx->res->json->{records} || []; 100 100 is(scalar @$records, 1, 'importRepo restores the earlier repo snapshot'); 101 - is($records->[0]{uri}, "at://$did/app.bsky.feed.post/before-import", 'imported repo keeps the earlier record URI'); 102 - is($records->[0]{value}{text}, 'state before import', 'imported repo restores the earlier record body'); 101 + my ($restored) = grep { ($_->{uri} // q()) eq "at://$did/app.bsky.feed.post/before-import" } @$records; 102 + ok($restored, 'imported repo keeps the earlier record URI'); 103 + is($restored->{value}{text}, 'state before import', 'imported repo restores the earlier record body'); 103 104 104 105 done_testing;
+9 -1
t/pds_smoke.t
··· 19 19 20 20 use Test::Mojo; 21 21 use ATProto::PDS; 22 + use ATProto::PDS::Repo::CAR qw(read_car); 22 23 23 24 my $root = File::Spec->rel2abs(File::Spec->catdir($Bin, '..')); 24 25 my $tmp = tempdir(CLEANUP => 1); ··· 68 69 })->status_is(200) 69 70 ->json_has('/uri') 70 71 ->json_has('/cid'); 72 + my $record_cid = $t->tx->res->json->{cid}; 71 73 72 74 $t->get_ok('/xrpc/com.atproto.repo.listRecords' => form => { 73 75 repo => $did, ··· 80 82 })->status_is(200) 81 83 ->json_has('/cid') 82 84 ->json_has('/rev'); 85 + my $latest_commit_cid = $t->tx->res->json->{cid}; 83 86 84 87 $t->get_ok('/xrpc/com.atproto.sync.getRepo' => form => { 85 88 did => $did, 86 89 })->status_is(200); 87 90 88 91 like($t->tx->res->headers->content_type // '', qr{application/vnd\.ipld\.car}, 'repo export is served as CAR'); 89 - ok(length($t->tx->res->body) > 0, 'repo export is non-empty'); 92 + my $repo_car = read_car($t->tx->res->body); 93 + is($repo_car->{roots}[0]->to_string, $latest_commit_cid, 'repo export roots the latest commit'); 94 + ok( 95 + scalar(grep { $_->{cid}->to_string eq $record_cid } @{ $repo_car->{blocks} || [] }), 96 + 'repo export includes the created record block', 97 + ); 90 98 91 99 done_testing;