App-karr
view release on metacpan or search on metacpan
t/104-board-identity-lifecycle.t view on Meta::CPAN
like( _run_karr( "$work/b", 'list', '--compact' )->{stdout},
qr/Original task/, 'B has the board' );
my $id_before = board_id_of( App::karr::Git->new( dir => "$work/b" ) );
ok defined $id_before, 'B carries the board identity';
_swap_in_foreign_board($work);
my $blocked = _run_karr( "$work/b", 'create', 'Another task' );
isnt( $blocked->{exit}, 0,
'a writing command on B fails instead of converging onto the foreign board' );
like( $blocked->{stderr}, qr/refusing to sync/, 'and says it refused' );
like( $blocked->{stderr}, qr/different board/, 'and what the remote became' );
like( $blocked->{stderr}, qr/accept-foreign-board/,
'and how to adopt the foreign board if that is really wanted' );
like( _run_karr( "$work/b", 'list', '--compact' )->{stdout},
qr/Original task/, 'B still has its own board while the question is open' );
# Way through number one: the remote is the truth now, adopt it.
my $adopted = _run_karr( "$work/b", 'sync', '--accept-foreign-board' );
is( $adopted->{exit}, 0, 'karr sync --accept-foreign-board succeeds' )
or diag $adopted->{stderr};
like( _run_karr( "$work/b", 'list', '--compact' )->{stdout},
qr/Foreign task/, 'B now carries the foreign board' );
unlike( _run_karr( "$work/b", 'list', '--compact' )->{stdout},
qr/Original task/, 'and the old board is gone' );
is( _run_karr( "$work/b", 'create', 'After the takeover' )->{exit}, 0,
'and writing commands work again' );
};
subtest 'end to end: sync --push republishes this board over the wrong remote' => sub {
my $work = _clone_pair();
is( _run_karr( "$work/a", 'init', '--name', 'Mine' )->{exit}, 0, 'board created' );
is( _run_karr( "$work/a", 'create', 'Precious task' )->{exit}, 0, 'and published' );
_swap_in_foreign_board($work);
my $blocked = _run_karr( "$work/a", 'create', 'Second task' );
isnt( $blocked->{exit}, 0, 'the swap stops the next writing command' );
like( $blocked->{stderr}, qr/refusing to sync/, 'with the refusal' );
is( _run_karr( "$work/a", 'sync', '--push' )->{exit}, 0,
'sync --push republishes this board over the foreign one' );
is( _run_karr( "$work/a", 'create', 'Third task' )->{exit}, 0,
'and ordinary commands resume once the remote agrees again' );
like( _run_karr( "$work/a", 'list', '--compact' )->{stdout},
qr/Precious task/, 'the board itself was never touched' );
};
subtest 'restore keeps the standing identity when the snapshot predates it' => sub {
my $repo = _repo();
my $git = App::karr::Git->new( dir => $repo );
my $store = App::karr::BoardStore->new( git => $git );
$store->save_config( App::karr::Config->default_config );
$store->ensure_board_id;
my $standing = $store->board_id;
ok defined $standing, 'setup: the board has an identity';
# A backup taken before identities existed carries no board-id. Installing
# it verbatim would strip the identity, and the push that follows would
# prune it off the remote too -- the board would disarm itself.
my $snapshot = $store->snapshot;
delete $snapshot->{refs}{'refs/karr/meta/board-id'};
ok $store->restore_snapshot($snapshot), 'the restore runs';
is $store->board_id, $standing,
'and the identity the board already had is still its identity';
};
subtest 'restore installs the identity a snapshot carries' => sub {
my $repo = _repo();
my $git = App::karr::Git->new( dir => $repo );
my $store = App::karr::BoardStore->new( git => $git );
$store->save_config( App::karr::Config->default_config );
$store->ensure_board_id;
my $snapshot = $store->snapshot;
my $own = $store->board_id;
# Same board: the id travels with the snapshot and comes back unchanged.
ok $store->restore_snapshot($snapshot), 'same-board restore runs';
is $store->board_id, $own, 'identity unchanged by its own snapshot';
# A foreign snapshot is a deliberate takeover: its id is installed as is.
$snapshot->{refs}{'refs/karr/meta/board-id'} = 'f' x 32 . "\n";
ok $store->restore_snapshot($snapshot), 'foreign restore runs';
is $store->board_id, 'f' x 32, 'a foreign snapshot re-keys the board on purpose';
};
done_testing;
( run in 0.384 second using v1.01-cache-2.11-cpan-4ef0a570458 )