blib/lib/App/karr/Role/DependencyCheck.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« blib/lib/App/karr/Cmd/Enable.pm ↑ Summary bin/karr »
1 # ABSTRACT: Warn when a card is taken up while its dependencies are unfinished
2  
3 package App::karr::Role::DependencyCheck;
4 our $VERSION = '0.602';
5 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use App::karr::CrossBoard;
Subroutine BEGIN: called CC=1 SCAR=2.6
7  
8 # What this role calls on its consumer, said out loud (ticket #128). It used to
9 # declare nothing, and got away with it only because every consumer happened to
10 # compose the roles that supply these: store from
11 # App::karr::Role::BoardDiscovery, find_task from App::karr::Role::BoardAccess,
12 # json from App::karr::Role::Output, quiet from
13 # App::karr::Role::SyncLifecycle. App::karr::Role::TaskMutation composes this
14 # role, so the next command to reach for the mutation path would have inherited
15 # methods whose collaborators nobody had checked for -- and found out at the
16 # moment a warning was due, as a "Can't locate object method", rather than at
17 # compile time.
18 #
19 # json is on the list since ticket #137 split the set-time helpers off into
20 # App::karr::Role::DependencyArgs. It could not be until then: this role also
21 # carried parse_dependency_ids and assert_dependencies_exist, and the command
22 # that composed it for those two alone -- create -- has no --json, so requiring
23 # json refused a consumer that never reaches the reporting half. Leaving it out
24 # was the narrower hole rather than none: `$self->json || $self->quiet`
25 # evaluates json first and unconditionally, so a consumer missing it broke on
26 # every warning, not only the ones without --json.
27 requires qw( store find_task json quiet );
28  
29  
30 # Keyed by task id rather than a flat list, because check_dependencies runs
31 # inside a compare-and-swap callback that re-runs when another agent gets in
32 # first (App::karr::Role::TaskMutation/update_task_guarded,
33 # App::karr::Cmd::Pick/_claim_under_lock). A list would grow one copy of every
34 # warning per attempt; a keyed slot is replaced by the attempt that wins.
35 has _dependency_warnings => (
36 is => 'ro',
37 default => sub { {} },
38 );
39  
40 sub check_dependencies {
41 my ( $self, $task, $new_status ) = @_;
42  
43 my $id = $task->id;
44 delete $self->_dependency_warnings->{$id};
45  
46 # A move into a terminal status is not taking work up, it is finishing it,
47 # and what a finished card was once waiting for is no longer anybody's
48 # decision to make. The board's own statuses answer this, not done/archived
49 # (tickets #67, #98).
50 return () if $self->store->is_terminal_status($new_status);
51  
52 my @deps = @{ $task->depends_on };
53 my @cross = App::karr::CrossBoard->needs_of($task);
54 return () unless @deps || @cross;
55  
56 my @warnings;
57 for my $dep_id (@deps) {
58 my $dep = $self->find_task($dep_id);
59  
60 # A deliberate divergence from the reference. kanban-md treats an id
61 # that is not on the board as *satisfied*
62 # (internal/board/filter.go:151-154): "Missing dependency IDs can occur
63 # after legacy hard-deletes. Treat as satisfied so dependents are
64 # recoverable via edit/cleanup." That reasoning is about not stranding a
65 # card, and it is sound there, where an unsatisfied dependency makes the
66 # card unpickable. Here nothing is blocked, so there is no card to
67 # strand -- and a dependency pointing at an id that does not exist is
68 # exactly the kind of thing whoever is about to start work wants told.
69 if ( !$dep ) {
70 push @warnings, sprintf
71 'Warning: task %s depends on task %s, which does not exist on this board',
72 $id, $dep_id;
73 next;
74 }
75  
76 next if $self->store->is_terminal_status( $dep->status );
77 push @warnings, sprintf
78 'Warning: task %s depends on task %s, which is still %s',
79 $id, $dep_id, $dep->status;
80 }
81  
82 # The cross-board half (ticket #192). Deliberately not resolved: the far
83 # board's state is behind a path this command does not have and must not
84 # invent, and a status change that reached into another repository to look
85 # one up would be doing transport nobody asked for. What is worth saying at
86 # the moment somebody takes the card up is that it is waiting on another
87 # board at all -- the same #123 point, one repository over -- and where to
88 # get the answer.
89 for my $ref (@cross) {
90 push @warnings, sprintf
91 'Warning: task %s waits on %s on another board (run "karr needs" for its state)',
92 $id, App::karr::CrossBoard->format_ref($ref);
93 }
94  
95 $self->_dependency_warnings->{$id} = \@warnings if @warnings;
96 return @warnings;
97 }
98  
99  
100 sub dependency_report {
101 my ( $self, $id ) = @_;
102  
103 my $warnings = $self->_dependency_warnings->{$id};
104 return () unless $warnings && @$warnings;
105  
106 print STDERR map { "$_\n" } @$warnings
107 unless $self->json || $self->quiet;
108  
109 return ( dependency_warnings => $warnings );
110 }
111  
112  
113 1;
114  
115 __END__
« blib/lib/App/karr/Cmd/Enable.pm ↑ Summary bin/karr »