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

filter: Statementstmt 20.7% 16 / 77 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 30.7% 4 / 13 Podpod 100% 4 / 4 totaltotal 12.4% 24 / 193 CC 36 SCAR 37.7
CC
36
Cov
10%
check_claim
90.0
_claim_refusal_hint
72.0
_parse_timeout
30.0
CRAP 43.4
« blib/lib/App/karr/Foundation/Executor.pm ↑ Summary blib/lib/App/karr/Cmd/Skill.pm »
1 # ABSTRACT: Shared claim timeout logic
2  
3 package App::karr::Role::ClaimTimeout;
4 2 our $VERSION = '0.602';
5 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # Loaded without importing, and every call below is qualified. A Moo::Role
7 # composes every sub in its package into its consumers, imported ones included,
8 # so `use Time::Piece;` here put its localtime/gmtime replacements on every
9 # command that composes this role (#105). Worse than the #38 cases, because
10 # those two shadow builtins: a future `sub localtime` on a command class would
11 # fight an inherited export and look like a core function misbehaving.
12 # App::karr::Role::Output and App::karr::Role::BoardDiscovery state the rule.
13 #
14 # Time::Piece is not a drop-in for that treatment -- replacing the builtins is
15 # its whole point -- so the two sites below were decided one at a time:
16 # ->strptime was already a class method and needs no import, and the gmtime in
17 # _claim_expired wants the overloaded object (the builtin returns a string in
18 # that scalar context, and the subtraction would be nonsense), so it is spelled
19 # Time::Piece::gmtime().
20 2 ▶use Time::Piece ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use App::karr::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 # Loaded without importing, for the reason spelled out in
23 # App::karr::Role::Output: a Moo::Role composes every sub in its package into
24 # its consumers, imported ones included, so `use App::karr::Error qw( ... )`
25 # here would quietly make those names methods on every command that composes
26 # this role. The refusal message is built with command_hint and original_argv,
27 # both called qualified below.
28 2 ▶use App::karr::Error ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # What this role calls on its consumer, said out loud (ticket #144; the rule is
31 # ticket #128's, and this is the last of the three mutation-path roles to get
32 # it). It declared nothing at all until then, and composed cleanly into
33 # anything, while claim_timeout_secs reads $self->store to find the board's
34 # configured claim_timeout -- store being App::karr::Role::BoardDiscovery's
35 # attribute, which every consumer happens to bring along via
36 # App::karr::Role::BoardAccess. That is the accident, not the guarantee: a
37 # consumer without it got check_claim regardless, and would have learned about
38 # the gap from inside a mutation as "Can't locate object method", on the one run
39 # where a task was actually claimed.
40 #
41 # json and quiet joined store in ticket #177, when check_claim stopped being a
42 # pure decision and started reporting the one case it lets through silently (see
43 # expired_claim_report). They are the same two names
44 # App::karr::Role::DependencyCheck declares for the same reason, and every
45 # consumer of this role already has both -- App::karr::Cmd::Unlock and
46 # App::karr::Cmd::Pick compose App::karr::Role::Output for json and reach quiet
47 # through App::karr::Role::SyncLifecycle, and App::karr::Role::TaskMutation's
48 # five commands do too. That is what kept this a widening of the contract rather
49 # than the role split ticket #137 needed: there, `create` composed
50 # DependencyCheck for its set-time half alone and had no --json to declare.
51 #
52 # Three names, not more. The other five calls in this file -- _parse_timeout,
53 # _parse_claim_stamp, _claim_expired, claim_timeout_secs and the _expired_claims
54 # attribute -- are defined right here, so the consumer never supplies them;
55 # requiring one would be worse than redundant, since Role::Tiny installs a
56 # role's methods into the consumer *before* it checks the requires
57 # (role_application_steps), so the check would find what the composition had
58 # just put there, in every consumer, always, and read as a promise that had
59 # been verified when nothing had. Unlike
60 # App::karr::Role::TaskMutation, which composes two roles and gets check_claim
61 # and check_dependencies from them, this role composes nothing -- so "the role's
62 # own" here means only "defined in this file".
63 #
64 # $self->claim appears once more below, in the =method check_claim synopsis. It
65 # is an example of what a command passes in, not a call this role makes, and no
66 # consumer is asked for it. t/147-claim-timeout-requires.t reads the calls out
67 # of this source with the POD stripped for exactly that reason.
68 2 requires qw( store json quiet );
69  
70  
71 # $fallback is what an absent or unparseable value means. It defaults to an
72 # hour, which is right for claim_timeout but far too long for lock_timeout --
73 # a lock covers one pick transaction, not a work session, so App::karr::Cmd::Pick
74 # passes its own (see LOCK_TIMEOUT_FALLBACK there).
75 #
76 # The whole Go duration grammar, not just ^\d+[hms]$: kanban-md writes
77 # claim_timeout with time.ParseDuration, so an imported `1h30m` has to mean
78 # ninety minutes here too instead of silently collapsing to the fallback
79 # (ticket #78). Anything unparseable -- including "7d", which Go rejects as
80 # well -- falls back. An explicit zero is not a failure and is honoured: `0s`
81 # is how a board says "locks never expire" (see App::karr::Cmd::Unlock), and
82 # swapping it for the default would silently turn that off. A bare `0` with no
83 # unit is caught by the falsy guard above and keeps its historical fallback.
84 0 ▶sub _parse_timeout {
Subroutine _parse_timeout: not called CC=5 SCAR=34.0
85 0 my ($self, $timeout_str, $fallback) = @_;
86 0 ▶ $fallback //= 3600;
Condition0%0/2
$fallback //= 3600
l!l
00
MC/DC0%0/1
$fallback //= 3600
$fallback
Truth table0%0/2
A
A= $fallback
Aresult
11
00
87 0 ▶ return $fallback unless $timeout_str;
Branch: 1 branch
BranchTrueFalseTotal
unless $timeout_str 0 0 0
88 0 my $secs = App::karr::Config->parse_duration($timeout_str);
89 0 ▶ return $fallback unless defined $secs && $secs >= 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $secs and $secs >= 0 0 0 0
Condition0%0/3
defined $secs and $secs >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $secs and $secs >= 0
defined $secs $secs >= 0
Truth table0%0/3
A and B
A= defined $secsB= $secs >= 0
ABresult
0X0
100
111
90 0 return $secs;
91 }
92  
93 # The board's configured claim timeout in seconds, so callers do not each have
94 # to remember the '1h' fallback.
95 0 ▶sub claim_timeout_secs {
Subroutine claim_timeout_secs: not called CC=2 SCAR=17.9
Pod documented
96 0 my ($self) = @_;
97 0 ▶ return $self->_parse_timeout( $self->store->effective_config->{claim_timeout} // '1h' );
Condition0%0/2
$self->store->effective_config->{"claim_timeout"} // "1h"
l!l
00
MC/DC0%0/1
$self->store->effective_config->{"claim_timeout"} // "1h"
$self->store->effective_config->{"claim_timeout"}
Truth table0%0/2
A
A= $self->store->effective_config->{"claim_timeout"}
Aresult
11
00
98 }
99  
100  
101 # karr and kanban-md both stamp claims with RFC3339, but not the same RFC3339.
102 # karr writes `gmtime->datetime . 'Z'` -- no fraction, always UTC. kanban-md
103 # writes Go's time.RFC3339Nano off the agent's local clock, verified against the
104 # real binary as 2026-08-09T17:28:46.449764553+02:00.
105 #
106 # The old parse stripped a trailing "Z" and handed the rest to a bare
107 # '%Y-%m-%dT%H:%M:%S', so the fraction and the offset were thrown away and the
108 # stamp was read as if it were UTC. A claim stamped +02:00 looked two hours
109 # younger than it was and never expired; one stamped -05:00 looked five hours
110 # older and was stolen while its owner was still working. Time::Piece also
111 # warned "Garbage at end of string in strptime" to STDERR on every single call,
112 # which meant every `karr pick` next to a kanban-md agent (ticket #57).
113 #
114 # So match the whole grammar instead: drop only the fractional seconds --
115 # sub-second precision cannot matter against a timeout measured in minutes --
116 # and hand the offset to strptime's %z, which is what actually normalises to
117 # UTC. Time::Piece's %z wants +hhmm rather than RFC3339's +hh:mm, and does not
118 # know "Z" at all, so both are normalised first. A stamp with no offset is read
119 # as UTC, which is what karr's own writer means by it.
120 #
121 # Because the format now matches the whole string, strptime has nothing left
122 # over to complain about and the STDERR noise goes away with it. A stamp that
123 # does not match at all returns undef and is treated as "not expired", the same
124 # conservative answer as before: never expiring is a stuck claim, wrongly
125 # expiring is a stolen one.
126 0 ▶sub _parse_claim_stamp {
Subroutine _parse_claim_stamp: not called CC=5 SCAR=34.0
127 0 my ($self, $stamp) = @_;
128 0 ▶ return undef unless defined $stamp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stamp 0 0 0
129 0 ▶ my ($civil, $offset) = $stamp =~ m{
Branch: 1 branch
BranchTrueFalseTotal
() = $stamp =~ / \A (\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}) # civil date and time (?: \. \d+ )? # fractional seconds, dropped ( Z | [+-]\d{2}:?\d{2} )? # UTC offset, or none \z /x or return undef 0 0 0
130 \A (\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}) # civil date and time
131 (?: \. \d+ )? # fractional seconds, dropped
132 ( Z | [+-]\d{2}:?\d{2} )? # UTC offset, or none
133 \z
134 }x or return undef;
135 0 ▶ $offset = '+0000' if !defined $offset || uc($offset) eq 'Z';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $offset or uc $offset eq "Z" 0 0 0
Condition0%0/3
not defined $offset or uc $offset eq "Z"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $offset or uc $offset eq "Z"
not defined $offset uc $offset eq "Z"
Truth table0%0/3
not(A) or B
A= not defined $offsetB= uc $offset eq "Z"
ABresult
1X1
011
000
136 0 $offset =~ s/://;
137 0 my $parsed = eval { Time::Piece->strptime( "$civil$offset", '%Y-%m-%dT%H:%M:%S%z' ) };
138 0 return $parsed;
139 }
140  
141 # Zero is not a very short window, it is the switch that turns expiry off --
142 # the one number here that is not read as a duration at all (ticket #232). That
143 # is the only reason this guard exists: every other value goes into the
144 # subtraction below and means what it says, so "simplifying" the line away
145 # looks harmless and restores the exact inversion it was written for. `0s` is
146 # how a board says claims are binding here, and the plain comparison made it
147 # say the opposite -- (now - claimed_at) > 0 is true of every claim older than
148 # a second, so the setting meant to protect a card was the setting that handed
149 # it to the next agent that asked, silently, seconds after the claim.
150 #
151 # kanban-md answers it the same way: internal/board/filter.go's IsUnclaimed
152 # asks `timeout > 0 && t.ClaimedAt != nil` and falls through to "still
153 # claimed" when the timeout is zero.
154 #
155 # Deliberately the same predicate, spelled the same way, as
156 # L<App::karr::Lock/expired>: the lock side has always read its own zero
157 # correctly (`lock_timeout: 0s`, see App::karr::Cmd::Unlock), and the two
158 # stayed out of step for as long as they did because they look alike without
159 # being the same code. They are not folded into one helper because a
160 # two-term boolean is the whole of the overlap while everything around it
161 # differs -- App::karr::Lock is a plain class in the storage layer, judges the
162 # age of a Git commit rather than a parsed RFC3339 stamp, brings its own TTL
163 # fallback, and puts the guard ahead of a ref read this role has no
164 # counterpart for. t/232-claim-timeout-zero-never-expires.t pins both answers
165 # in one file so a change to either side alone goes red.
166 #
167 # A negative timeout cannot arrive from a board -- _parse_timeout sends it to
168 # the fallback -- but is answered the same way as zero for the same reason
169 # App::karr::Lock/expired does: "not a positive window" is the whole question
170 # here, and no caller should have to know which side of zero it landed on.
171 0 ▶sub _claim_expired {
Subroutine _claim_expired: not called CC=5 SCAR=34.0
172 0 my ($self, $task, $timeout_secs) = @_;
173 0 ▶ return 0 unless $timeout_secs && $timeout_secs > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $timeout_secs and $timeout_secs > 0 0 0 0
Condition0%0/3
$timeout_secs and $timeout_secs > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$timeout_secs and $timeout_secs > 0
$timeout_secs $timeout_secs > 0
Truth table0%0/3
A and B
A= $timeout_secsB= $timeout_secs > 0
ABresult
0X0
100
111
174 0 ▶ return 0 unless $task->has_claimed_at;
Branch: 1 branch
BranchTrueFalseTotal
unless $task->has_claimed_at 0 0 0
175 0 my $claimed = $self->_parse_claim_stamp( $task->claimed_at );
176 0 ▶ return 0 unless defined $claimed;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $claimed 0 0 0
177 0 return (Time::Piece::gmtime() - $claimed) > $timeout_secs;
178 }
179  
180 # The claim test as one question, because two callers now ask it and karr may
181 # only have one answer (ticket #252). It was three lines in the middle of
182 # App::karr::Role::PickRules/pickable, with `return 0 if $task->has_blocked` on
183 # the very next line, so `karr list --unclaimed` could not borrow it by calling
184 # pickable with neutralised filters: the blocked line came along, --unclaimed
185 # would have meant "free AND not blocked", and `list --blocked --unclaimed`
186 # would have been permanently empty. kanban-md's IsUnclaimed
187 # (internal/board/filter.go) asks about the claim and nothing else, and so does
188 # this.
189 #
190 # check_claim is not this question and cannot be made into it: it dies instead
191 # of answering, lets the caller through by name, excuses a card in a terminal
192 # status, and records what it let past into _expired_claims. This one takes no
193 # claimant, keeps no exception, writes nothing, and answers about the card
194 # alone -- which is why it can be asked once per card across a whole board.
195 #
196 # `claimed_by: ""` is unclaimed, the case that came here from pickable
197 # unchanged: kanban-md's omitempty writes the key only when it is non-empty,
198 # but a card it read and rewrote -- or any hand-written one -- can carry the
199 # empty string, and Moo's predicate calls that "set". Every imported kanban-md
200 # card looked held (ticket #59). check_claim's first line spells the same test
201 # for the same reason, and the two have to agree or a task `pick` refuses is a
202 # task `move` accepts.
203 #
204 # $timeout is optional so a single call reads as a question about one card;
205 # pass it explicitly when asking about many, so one window covers the run
206 # rather than re-reading the board config per card. `//` and not `||`: 0 is a
207 # window of no length, not an absent one -- see _claim_expired, and ticket
208 # #232 for what conflating the two did.
209 0 ▶sub claim_held {
Subroutine claim_held: not called CC=5 SCAR=34.0
Pod documented
210 0 my ( $self, $task, $timeout ) = @_;
211 0 ▶ return 0 unless $task->has_claimed_by && length $task->claimed_by;
Branch: 1 branch
BranchTrueFalseTotal
unless $task->has_claimed_by and length $task->claimed_by 0 0 0
Condition0%0/3
$task->has_claimed_by and length $task->claimed_by
!ll&&!rl&&r
000
MC/DC0%0/2
$task->has_claimed_by and length $task->claimed_by
$task->has_claimed_by length $task->claimed_by
Truth table0%0/3
A and B
A= $task->has_claimed_byB= length $task->claimed_by
ABresult
0X0
100
111
212 0 ▶ return $self->_claim_expired( $task, $timeout // $self->claim_timeout_secs ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->_claim_expired($task, $timeout // $self->claim_timeout_secs) ? : 0 0 0
Condition0%0/3
$timeout // $self->claim_timeout_secs
l!l&&r!l&&!r
000
MC/DC0%0/2
$timeout // $self->claim_timeout_secs
$timeout $self->claim_timeout_secs
Truth table0%0/3
A // B
A= $timeoutB= $self->claim_timeout_secs
ABresult
1X1
011
000
213 }
214  
215  
216 # Keyed by task id rather than a flat list, for the reason spelled out above
217 # check_claim: the check runs inside a compare-and-swap callback that re-runs on
218 # contention, and `karr delete` applies it twice for one card. A keyed slot is
219 # replaced by whichever call comes last; a list would grow a copy per attempt.
220 # Same shape, and the same reason, as
221 # App::karr::Role::DependencyCheck/_dependency_warnings.
222 has _expired_claims => (
223 is => 'ro',
224 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
225 2 );
226  
227 # The one claim-ownership rule, mirroring kanban-md's task.CheckClaim
228 # (internal/task/validate.go): an unclaimed task is free, the current claimant
229 # may always proceed, and an expired claim no longer blocks anybody. Anything
230 # else belongs to an agent who is still working on it, and the mutation is
231 # refused rather than silently taking the claim over (ticket #56).
232 #
233 # Four deliberate differences from kanban-md:
234 #
235 # * an expired claim is not cleared here. kanban-md's CheckClaim blanks
236 # ClaimedBy as a side effect of asking the question; in karr that would
237 # change what the require_claim check in
238 # L<App::karr::Role::TaskMutation/apply_status_change> sees a few lines
239 # later, turning an allowed move into a refused one. Expired claims are
240 # reaped where they always were, by `karr pick`.
241 #
242 # * the refusal names the way out, in the shape ticket k263 settled on: the
243 # prose line, then `karr edit ID --release` -- the one door that needs no
244 # claim knowledge -- then, where the caller's own argv was recorded, the
245 # caller's own command line with `--claim HOLDER` added, so the last line
246 # is the invocation that would have worked. kanban-md's hint is the same
247 # idea ("If this is you, add: --claim X"); karr's is followable because
248 # every command that applies this rule now takes --claim, delete and
249 # archive included (ticket #269).
250 #
251 # * the expired case is recorded, because it used to be the one answer this
252 # method gave -- here and in kanban-md both -- with nothing said anywhere
253 # (ticket #177). A live claim held by somebody else is refused loudly and
254 # the refusal names the holder, which is how #176's confused agent gets its
255 # own lost claim name back; then the claim expires and that signal
256 # disappears, at the moment it is most useful. `move` and `handoff --claim`
257 # re-stamp claimed_by on the way through, so the previous holder is gone
258 # from the card too, and karr-foundation, which attributes stalls per claim
259 # name, is left attributing to a name nobody ever held.
260 #
261 # * a task in a terminal status is not guarded at all, whoever holds the
262 # claim on it. kanban-md's CheckClaim never looks at the status, so this
263 # one is karr's rule rather than parity, and it comes from karr's own
264 # vocabulary: CONTEXT.md defines a Claim as the lease an agent holds
265 # *while working* a task, calls it released once the task reaches a
266 # terminal status, and keeps claimed_by there for provenance and interop
267 # only. That is not a private reading either -- `karr board` already prints
268 # no claimant on a finished card and leaves it out of its "N claimed"
269 # footer, both keyed on the very
270 # L<App::karr::Config/is_terminal_status> asked here, and `karr pick`
271 # refuses to hand a terminal card out again
272 # (L<App::karr::Role::PickRules>), so nothing can route a second agent onto
273 # finished work through this door. The code was the one place still
274 # treating the field as a live lease: the agent that finished a card went
275 # on guarding it for the rest of claim_timeout -- an hour by default, and
276 # precisely the hour in which the closing note gets appended, the card gets
277 # archived, or someone reopens it. Worse, the refusal demanded a name the
278 # board deliberately hides on exactly those cards, so the way through was
279 # to read it off `karr show`. And it never was a lock: `karr edit ID
280 # --release` takes any claim off without knowing whose it is, which made
281 # the rule two commands instead of one for whoever knew the way round and a
282 # dead end for everybody else (ticket #223). What still protects a finished
283 # card is what protects every card here: update_task_guarded's
284 # compare-and-swap, which is about concurrent writes and not about
285 # ownership.
286 #
287 # The refusal is deliberately not the only door, and the message says both
288 # doors out loud. `karr edit ID --release` takes any claim off without knowing
289 # whose it is -- the release bypasses this check entirely -- while `karr edit
290 # ID --claim NAME` is refused against a live claim held by somebody else and
291 # succeeds only when the claim has expired (and then reports the takeover,
292 # #177). That asymmetry is deliberate and matches kanban-md: release is the
293 # escape hatch, and a live claim is not stealable by name. Naming the release
294 # is what keeps a caller who is not the holder from being left staring at a
295 # claim they cannot satisfy.
296 #
297 # That last case is checked last, after the expiry test rather than before it,
298 # although either order allows the same calls. The difference is the record: a
299 # terminal card whose claim had *also* expired keeps reporting the takeover it
300 # reported before (see expired_claim_report and #177), instead of losing that
301 # line to a case that answers earlier and says nothing.
302 #
303 # Recorded, not printed, and for the same reason as
304 # App::karr::Role::DependencyCheck: check_claim runs inside
305 # App::karr::Role::TaskMutation/update_task_guarded's callback, which re-runs
306 # when another agent gets in first, so a print here would come out once per
307 # attempt -- and once for an attempt that was then discarded. A slot keyed by
308 # task id and cleared on entry is replaced by the attempt that wins instead,
309 # which is also what collapses `karr delete`'s two checks (once outside the
310 # guard to decide about the prompt, once inside it) into one line.
311 #
312 # What is *not* done here: nothing is refused that was not refused before, and
313 # no new state goes on the card. Taking over an expired claim is the documented
314 # purpose of claim_timeout, so this makes it audible, not harder. And the
315 # takeover is not the same event as the holder outliving its own timeout: the
316 # claimant-matches case returns above without reaching this, so a long-running
317 # agent never gets warned about itself.
318 0 ▶sub check_claim {
Subroutine check_claim: not called CC=9 SCAR=45.0
Pod documented
319 0 my ($self, $task, $claimant) = @_;
320 0 delete $self->_expired_claims->{ $task->id };
321 0 ▶ return 1 unless $task->has_claimed_by && length $task->claimed_by;
Branch: 1 branch
BranchTrueFalseTotal
unless $task->has_claimed_by and length $task->claimed_by 0 0 0
Condition0%0/3
$task->has_claimed_by and length $task->claimed_by
!ll&&!rl&&r
000
MC/DC0%0/2
$task->has_claimed_by and length $task->claimed_by
$task->has_claimed_by length $task->claimed_by
Truth table0%0/3
A and B
A= $task->has_claimed_byB= length $task->claimed_by
ABresult
0X0
100
111
322 0 ▶ return 1 if defined $claimant && length $claimant && $task->claimed_by eq $claimant;
Branch: 1 branch
BranchTrueFalseTotal
if defined $claimant and length $claimant and $task->claimed_by eq $claimant 0 0 0
Condition0%0/6
defined $claimant and length $claimant and $task->claimed_by eq $claimant
!ll&&!rl&&r
000
defined $claimant and length $claimant
!ll&&!rl&&r
000
MC/DC0%0/3
defined $claimant and length $claimant and $task->claimed_by eq $claimant
defined $claimant length $claimant $task->claimed_by eq $claimant
Truth table0%0/4
A and B and C
A= defined $claimantB= length $claimantC= $task->claimed_by eq $claimant
ABCresult
0XX0
10X0
1100
1111
323 0 ▶ if ( $self->_claim_expired( $task, $self->claim_timeout_secs ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_claim_expired($task, $self->claim_timeout_secs)) 0 0 0
324 0 $self->_expired_claims->{ $task->id } = {
325 held_by => $task->claimed_by,
326 claimed_at => $task->claimed_at,
327 };
328 0 return 1;
329 }
330 0 ▶ return 1 if $self->store->is_terminal_status( $task->status );
Branch: 1 branch
BranchTrueFalseTotal
if $self->store->is_terminal_status($task->status) 0 0 0
331 0 my $holder = $task->claimed_by;
332 0 my $msg = sprintf( "Task %d is claimed by %s:\n", $task->id, $holder )
333 . App::karr::Error::command_hint( 'edit', $task->id, '--release' ) . "\n";
334 0 my @hint = $self->_claim_refusal_hint($task);
335 0 ▶ $msg .= App::karr::Error::command_hint(@hint) . "\n" if @hint;
Branch: 1 branch
BranchTrueFalseTotal
if @hint 0 0 0
336 0 die $msg;
337 }
338  
339 # The caller's own command line with --claim HOLDER added, or nothing. The
340 # words come from App::karr::Error/original_argv, which bin/karr records before
341 # either argv rewrite and the in-process test runner records through the shared
342 # App::karr::Dispatch path -- and which nothing else records, so a library
343 # caller or a direct check_claim gets no working-command line at all. That is
344 # the k263 rule: a suggestion built from placeholders would only spell the
345 # "Usage:" line a second time, and the release line above is always the honest
346 # answer for a caller whose words are unknown.
347 #
348 # An existing --claim VALUE is replaced rather than appended to, so `karr
349 # handoff 1 --claim carol` is answered with `karr handoff 1 --claim bob` and
350 # not with a second --claim that Getopt::Long would refuse. Both spellings the
351 # caller could have typed are handled: the space form and the `=` form.
352 0 ▶sub _claim_refusal_hint {
Subroutine _claim_refusal_hint: not called CC=8 SCAR=42.8
353 0 my ( $self, $task ) = @_;
354 0 my $argv = App::karr::Error::original_argv();
355 0 ▶ return () unless $argv && @$argv;
Branch: 1 branch
BranchTrueFalseTotal
unless $argv and @$argv 0 0 0
Condition0%0/3
$argv and @$argv
!ll&&!rl&&r
000
MC/DC0%0/2
$argv and @$argv
$argv @$argv
Truth table0%0/3
A and B
A= $argvB= @$argv
ABresult
0X0
100
111
356 0 my @tokens = @$argv;
357 0 my $holder = $task->claimed_by;
358 0 my $replaced = 0;
359 0 for my $i ( 0 .. $#tokens ) {
360 0 ▶ if ( $tokens[$i] eq '--claim' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[$i] eq "--claim") 0 0 0
361 0 ▶ $tokens[ $i + 1 ] = $holder if defined $tokens[ $i + 1 ];
Branch: 1 branch
BranchTrueFalseTotal
if defined $tokens[$i + 1] 0 0 0
362 0 $replaced = 1;
363 0 last;
364 }
365 0 ▶ if ( $tokens[$i] =~ /\A--claim=(.*)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[$i] =~ /\A--claim=(.*)\z/) 0 0 0
366 0 $tokens[$i] = '--claim=' . $holder;
367 0 $replaced = 1;
368 0 last;
369 }
370 }
371 0 ▶ push @tokens, '--claim', $holder unless $replaced;
Branch: 1 branch
BranchTrueFalseTotal
unless $replaced 0 0 0
372 0 return @tokens;
373 }
374  
375  
376 # The channels are App::karr::Role::DependencyCheck/dependency_report's, not a
377 # second convention: STDERR keeps STDOUT parseable, --json carries the same fact
378 # as data because a JSON consumer never reads STDERR, and --quiet silences the
379 # human copy only -- the pair is data, not chatter, so a drain loop that does not
380 # want the line can still read who held the card.
381 #
382 # The pair is a structure rather than the sentence DependencyCheck ships,
383 # because the caller this exists for is karr-foundation, which attributes stalls
384 # per claim name and must not have to parse that name out of English.
385 0 ▶sub expired_claim_report {
Subroutine expired_claim_report: not called CC=4 SCAR=30.0
Pod documented
386 0 my ( $self, $id ) = @_;
387  
388 0 my $expired = $self->_expired_claims->{$id};
389 0 ▶ return () unless $expired;
Branch: 1 branch
BranchTrueFalseTotal
unless $expired 0 0 0
390  
391 printf STDERR
392 "Warning: task %s: overriding the expired claim held by %s (claimed %s)\n",
393 $id, $expired->{held_by}, $expired->{claimed_at}
394 0 ▶ unless $self->json || $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->json or $self->quiet 0 0 0
Condition0%0/3
$self->json or $self->quiet
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->json or $self->quiet
$self->json $self->quiet
Truth table0%0/3
A or B
A= $self->jsonB= $self->quiet
ABresult
1X1
011
000
395  
396 0 return ( expired_claim => $expired );
397 }
398  
399  
400 2 1;
401  
402 __END__
« blib/lib/App/karr/Foundation/Executor.pm ↑ Summary blib/lib/App/karr/Cmd/Skill.pm »