lib/App/teai/Hook.pm

filter: Statementstmt 16.3% 53 / 325 Branchbran 0.0% 0 / 200 Conditioncond 0.0% 0 / 193 MC/DCmcdc 0.0% 0 / 103 Subroutinesub 17.1% 12 / 70 Podpod 100% 7 / 7 totaltotal 8.0% 72 / 898 CC 189 SCAR 42.8
CC
189
Cov
7%
__ANON__
210.0
_stop_waiter
210.0
_wait
182.0
CRAP 72.4
« lib/App/teai/Dash/Rounds.pm ↑ Summary lib/App/teai/Dash.pm »
1 package App::teai::Hook;
2 1 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Cpanel::JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use EV;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Fcntl qw(:flock O_RDONLY O_WRONLY O_RDWR O_CREAT O_EXCL O_NONBLOCK);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use App::teai::Bus;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use App::teai::Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use App::teai::Err ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use App::teai::Presence ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use App::teai::Wire ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 our $VERSION = '0.08';
15  
16 1 my $MAX_STDIN = 4 * 1048576;
17 1 my $BOUND = 5;
18 1 my $FAST_BOUND = 4.5;
19 1 my $LOCK_RETRY = 0.01;
20 1 my $CURSOR_RE = qr/\A(\d+) ([\d.]+)\n?\z/;
21 1 my $POLL = 1;
22 1 my $SETTLE = 2;
23 1 my $INTERVAL = 60;
24 1 my $STOP_WAIT = 2;
25 1 my $TICK_LOCK = 0.5;
26 1 my $MEMO_TTL = 30;
27 1 my %SHELL = map { $_ => 1 } qw(sh bash dash zsh);
28 1 my %NEW_CONTEXT = map { $_ => 1 } qw(startup resume clear);
29 1 my ($HOLD, $STOPPED) = (0, 0);
30  
31 0 ▶sub _stop (@) { $HOLD ? ($STOPPED = 1) : POSIX::_exit(0) }
Subroutine _stop: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$HOLD ? : 0 0 0
32  
33 0 ▶sub _catch () {
Subroutine _catch: not called CC=4 SCAR=30.0
34 0 ($HOLD, $STOPPED) = (0, 0);
35 0 ▶ $SIG{$_} = \&_stop for 'INT', 'TERM', (($SIG{HUP} // '') eq 'IGNORE' ? () : 'HUP');
Branch: 1 branch
BranchTrueFalseTotal
($SIG{'HUP'} // '') eq 'IGNORE' ? : 0 0 0
Condition0%0/2
$SIG{"HUP"} // ""
l!l
00
MC/DC0%0/1
$SIG{"HUP"} // ""
$SIG{"HUP"}
Truth table0%0/2
A
A= $SIG{"HUP"}
Aresult
11
00
36 }
37  
38 0 ▶sub _release () {
Subroutine _release: not called CC=2 SCAR=17.9
39 0 $HOLD = 0;
40 0 ▶ POSIX::_exit(0) if $STOPPED;
Branch: 1 branch
BranchTrueFalseTotal
if $STOPPED 0 0 0
41 }
42  
43 0 ▶sub notice ($n) { "teai: $n new message" . ($n == 1 ? '' : 's') . ' - call teai_inbox or run teai inbox' }
Subroutine notice: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 0 0 0
44  
45 0 ▶sub _locked ($session, $until, $code) {
Subroutine _locked: not called CC=5 SCAR=34.0
46 0 ▶ $until //= App::teai::Bus::now() + $FAST_BOUND;
Condition0%0/2
$until //= App::teai::Bus::now() + $FAST_BOUND
l!l
00
MC/DC0%0/1
$until //= App::teai::Bus::now() + $FAST_BOUND
$until
Truth table0%0/2
A
A= $until
Aresult
11
00
47 0 my $dir = App::teai::Config::runtime_dir();
48 0 ▶ sysopen my $lock, "$dir/$session.wake.lock", O_RDWR | O_CREAT, 0600 or return;
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $lock, "$dir/$session.wake.lock", 66, 384 or return 0 0 0
49 0 ▶ until (flock $lock, LOCK_EX | LOCK_NB) {
Branch: 1 branch
BranchTrueFalseTotal
unless (flock $lock, 6) 0 0 0
50 0 ▶ return if App::teai::Bus::now() >= $until;
Branch: 1 branch
BranchTrueFalseTotal
if App::teai::Bus::now() >= $until 0 0 0
51 0 Time::HiRes::sleep($LOCK_RETRY);
52 }
53 0 return $code->("$dir/$session.wake");
54 }
55  
56 0 ▶sub _read ($path) {
Subroutine _read: not called CC=5 SCAR=34.0
57 0 ▶ sysopen my $fh, $path, O_RDONLY | O_NONBLOCK or return (0, 0);
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $fh, $path, 2048 or return 0, 0 0 0 0
58 0 my $n = sysread $fh, my $text, 128;
59 0 ▶ return $n && $n < 128 && $text =~ $CURSOR_RE ? ($1, $2) : (0, 0);
Branch: 1 branch
BranchTrueFalseTotal
$n && $n < 128 && $text =~ /$CURSOR_RE/u ? : 0 0 0
Condition0%0/6
$n and $n < 128 and $text =~ /$CURSOR_RE/u
!ll&&!rl&&r
000
$n and $n < 128
!ll&&!rl&&r
000
MC/DC0%0/3
$n and $n < 128 and $text =~ /$CURSOR_RE/u
$n $n < 128 $text =~ /$CURSOR_RE/u
Truth table0%0/4
A and B and C
A= $nB= $n < 128C= $text =~ /$CURSOR_RE/u
ABCresult
0XX0
10X0
1100
1111
60 }
61  
62 0 ▶sub cursor ($session, $until = undef) {
Subroutine cursor: not called CC=3 SCAR=17.3
Pod documented
63 0 my @c = eval { _locked($session, $until, \&_read) };
64 1 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
65 0 ▶ return @c ? ($c[0] + 0, $c[1] + 0) : (0, 0);
Branch: 1 branch
BranchTrueFalseTotal
@c ? : 0 0 0
66 }
67  
68 0 ▶sub _put ($fh, $text) {
Subroutine _put: not called CC=5 SCAR=34.0
69 0 my $off = 0;
70 0 ▶ while ($off < length $text) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off < length $text) 0 0 0
71 0 my $n = syswrite $fh, $text, length($text) - $off, $off;
72 0 ▶ if ($n) { $off += $n }
Branch: 2 branches
BranchTrueFalseTotal
if ($n) { } 0 0 0
elsif (defined $n or not $!{'EINTR'}) { } 0 0 0
73 0 ▶ elsif (defined $n || !$!{EINTR}) { return 0 }
Condition0%0/3
defined $n or not $!{"EINTR"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $n or not $!{"EINTR"}
defined $n not $!{"EINTR"}
Truth table0%0/3
A or not(B)
A= defined $nB= not $!{"EINTR"}
ABresult
1X1
011
000
74 }
75 0 return 1;
76 }
77  
78 0 ▶sub _stage ($path, $line) {
Subroutine _stage: not called CC=5 SCAR=34.0
79 0 ▶ return undef unless $line =~ $CURSOR_RE;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /$CURSOR_RE/u 0 0 0
80 0 my $tmp = "$path.$$";
81 0 unlink $tmp;
82 0 ▶ sysopen my $fh, $tmp, O_WRONLY | O_CREAT | O_EXCL, 0600 or return undef;
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $fh, $tmp, 193, 384 or return undef 0 0 0
83 0 my $ok = _put($fh, $line);
84 0 ▶ return $tmp if close($fh) && $ok;
Branch: 1 branch
BranchTrueFalseTotal
if close $fh and $ok 0 0 0
Condition0%0/3
close $fh and $ok
!ll&&!rl&&r
000
MC/DC0%0/2
close $fh and $ok
close $fh $ok
Truth table0%0/3
A and B
A= close $fhB= $ok
ABresult
0X0
100
111
85 0 unlink $tmp;
86 0 return undef;
87 }
88  
89 0 ▶sub _due ($r, $seq) {
Subroutine _due: not called CC=6 SCAR=37.4
90 return $r && $r->{pending} > 0 && $r->{latest} > $seq
91 0 ▶ && ($r->{latest} > $r->{delivered} || $r->{floor} >= $seq) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$r && $r->{'pending'} > 0 && $r->{'latest'} > $seq && ($r->{'latest'} > $r->{'delivered'} || $r->{'floor'} >= $seq) ? : 0 0 0
Condition0%0/12
$r and $r->{"pending"} > 0 and $r->{"latest"} > $seq and $r->{"latest"} > $r->{"delivered"} || $r->{"floor"} >= $seq
!ll&&!rl&&r
000
$r and $r->{"pending"} > 0 and $r->{"latest"} > $seq
!ll&&!rl&&r
000
$r and $r->{"pending"} > 0
!ll&&!rl&&r
000
$r->{"latest"} > $r->{"delivered"} or $r->{"floor"} >= $seq
l!l&&r!l&&!r
000
MC/DC0%0/5
$r and $r->{"pending"} > 0 and $r->{"latest"} > $seq and $r->{"latest"} > $r->{"delivered"} || $r->{"floor"} >= $seq
$r $r->{"pending"} > 0 $r->{"latest"} > $seq $r->{"latest"} > $r->{"delivered"} $r->{"floor"} >= $seq
Truth table0%0/6
A and B and C and D or E
A= $rB= $r->{"pending"} > 0C= $r->{"latest"} > $seqD= $r->{"latest"} > $r->{"delivered"}E= $r->{"floor"} >= $seq
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
92 }
93  
94 0 ▶sub _commit ($path, $r, $out, $epoch = undef) {
Subroutine _commit: not called CC=9 SCAR=45.0
95 0 my ($seq, $was) = _read($path);
96 0 ▶ return 0 if !_due($r, $seq) || -d $path;
Branch: 1 branch
BranchTrueFalseTotal
if not _due($r, $seq) or -d $path 0 0 0
Condition0%0/3
not _due($r, $seq) or -d $path
l!l&&r!l&&!r
000
MC/DC0%0/2
not _due($r, $seq) or -d $path
not _due($r, $seq) -d $path
Truth table0%0/3
not(A) or B
A= not _due($r, $seq)B= -d $path
ABresult
1X1
011
000
97 0 ▶ my $tmp = _stage($path, "$r->{latest} " . ($epoch // $was) . "\n") // return 0;
Condition0%0/5
_stage($path, qq[$r->{"latest"} ] . ($epoch // $was) . "\n") // (return 0)
l!l
00
$epoch // $was
l!l&&r!l&&!r
000
MC/DC0%0/1
_stage($path, qq[$r->{"latest"} ] . ($epoch // $was) . "\n") // (return 0)
_stage($path, qq[$r->{"latest"} ] . ($epoch // $was) . "\n")
MC/DC0%0/2
$epoch // $was
$epoch $was
Truth table0%0/2
A
A= _stage($path, qq[$r->{"latest"} ] . ($epoch // $was) . "\n")
Aresult
11
00
Truth table0%0/3
A // B
A= $epochB= $was
ABresult
1X1
011
000
98 0 ▶ my $rc = !_put($out, notice($r->{pending}) . "\n") ? -1 : !rename($tmp, $path) ? -2 : 1;
Branch: 2 branches
BranchTrueFalseTotal
!_put($out, notice($r->{'pending'}) . "\n") ? : 0 0 0
!rename($tmp, $path) ? : 0 0 0
99 0 ▶ if ($rc < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc < 0) 0 0 0
100 0 local $!;
101 0 unlink $tmp;
102 0 return $rc;
103 }
104 0 return 1;
105 }
106  
107 0 ▶sub announce ($session, $r, $out, $epoch = undef, $until = undef) {
Subroutine announce: not called CC=4 SCAR=30.0
Pod documented
108 0 ▶ return eval { _locked($session, $until, sub ($path) { _commit($path, $r, $out, $epoch) }) } // 0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/2
eval { do { _locked($session, $until, sub ($path) { _commit($path, $r, $out, $epoch); } ) } } // 0
l!l
00
MC/DC0%0/1
eval { do { _locked($session, $until, sub ($path) { _commit($path, $r, $out, $epoch); } ) } } // 0
eval { do { _locked($session, $until, sub ($path) { _commit($path, $r, $out, $epoch); } ) } }
Truth table0%0/2
A
A= eval { do { _locked($session, $until, sub ($path) { _commit($path, $r, $out, $epoch); } ) } }
Aresult
11
00
109 }
110  
111 0 ▶sub probe ($bus, $session, $cb, $memo = undef) {
Subroutine probe: not called CC=2 SCAR=17.9
Pod documented
112 0 ▶ $bus->consumer_info($session, sub ($info, $err = undef) {
Subroutine __ANON__: not called CC=14 SCAR=53.5
113 0 ▶ return $cb->(undef, $err) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 0 0 0
114 0 ▶ unless ($info) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($info) 0 0 0
115 0 ▶ %$memo = () if $memo;
Branch: 1 branch
BranchTrueFalseTotal
if $memo 0 0 0
116 0 my %none = (pending => 0, latest => 0, delivered => 0, floor => 0);
117 0 ▶ return $bus->removed($session, sub ($gone, $e = undef) { $cb->({ %none, ($gone ? (removed => 1) : ()) }) });
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
$gone ? : 0 0 0
118 }
119 0 ▶ my @n = map { $info->{$_} // 0 } qw(num_pending num_ack_pending);
Condition0%0/2
$info->{$_} // 0
l!l
00
MC/DC0%0/1
$info->{$_} // 0
$info->{$_}
Truth table0%0/2
A
A= $info->{$_}
Aresult
11
00
120 0 ▶ my ($delivered, $floor) = map { ($info->{$_} // {})->{stream_seq} // 0 } qw(delivered ack_floor);
Condition0%0/4
+($info->{$_} // {})->{"stream_seq"} // 0
l!l
00
$info->{$_} // {}
l!l
00
MC/DC0%0/1
+($info->{$_} // {})->{"stream_seq"} // 0
$info->{$_}
Truth table0%0/2
A
A= $info->{$_}
Aresult
11
00
121 0 my %r = (pending => $n[0] + $n[1], latest => 0, delivered => $delivered, floor => $floor);
122 0 ▶ unless ($r{pending}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r{"pending"}) 0 0 0
123 0 ▶ %$memo = () if $memo;
Branch: 1 branch
BranchTrueFalseTotal
if $memo 0 0 0
124 0 return $cb->(\%r);
125 }
126 0 my $mark = "@n $delivered";
127 return $cb->({ %r, latest => $memo->{latest} })
128 0 ▶ if $memo && ($memo->{mark} // '') eq $mark && App::teai::Bus::now() < $memo->{until};
Branch: 1 branch
BranchTrueFalseTotal
if $memo and ($memo->{"mark"} // "") eq $mark and App::teai::Bus::now() < $memo->{"until"} 0 0 0
Condition0%0/8
$memo and ($memo->{"mark"} // "") eq $mark and App::teai::Bus::now() < $memo->{"until"}
!ll&&!rl&&r
000
$memo and ($memo->{"mark"} // "") eq $mark
!ll&&!rl&&r
000
$memo->{"mark"} // ""
l!l
00
MC/DC0%0/3
$memo and ($memo->{"mark"} // "") eq $mark and App::teai::Bus::now() < $memo->{"until"}
$memo $memo->{"mark"} App::teai::Bus::now() < $memo->{"until"}
Truth table0%0/4
A and B and C
A= $memoB= $memo->{"mark"}C= App::teai::Bus::now() < $memo->{"until"}
ABCresult
0XX0
10X0
1100
1111
129 0 ▶ $bus->latest_seq($session, sub ($latest, $e = undef) {
Subroutine __ANON__: not called CC=6 SCAR=37.4
130 0 ▶ return $cb->(undef, $e // 'no sequence in the reply') unless defined $latest && $latest =~ /\A\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $latest and $latest =~ /\A\d+\z/u 0 0 0
Condition0%0/5
defined $latest and $latest =~ /\A\d+\z/u
!ll&&!rl&&r
000
$e // "no sequence in the reply"
l!l
00
MC/DC0%0/2
defined $latest and $latest =~ /\A\d+\z/u
defined $latest $latest =~ /\A\d+\z/u
MC/DC0%0/1
$e // "no sequence in the reply"
$e
Truth table0%0/3
A and B
A= defined $latestB= $latest =~ /\A\d+\z/u
ABresult
0X0
100
111
Truth table0%0/2
A
A= $e
Aresult
11
00
131 0 ▶ %$memo = (mark => $mark, latest => $latest, until => App::teai::Bus::now() + _knob('TEAI_TEST_WAKE_MEMO', $MEMO_TTL)) if $memo;
Branch: 1 branch
BranchTrueFalseTotal
if $memo 0 0 0
132 0 $cb->({ %r, latest => $latest });
133 0 });
134 0 });
135 }
136  
137 0 ▶sub _stat ($pid, $proc = '/proc') {
Subroutine _stat: not called CC=10 SCAR=47.0
138 0 ▶ return unless defined $pid && $pid =~ /\A[1-9]\d*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid and $pid =~ /\A[1-9]\d*\z/u 0 0 0
Condition0%0/3
defined $pid and $pid =~ /\A[1-9]\d*\z/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pid and $pid =~ /\A[1-9]\d*\z/u
defined $pid $pid =~ /\A[1-9]\d*\z/u
Truth table0%0/3
A and B
A= defined $pidB= $pid =~ /\A[1-9]\d*\z/u
ABresult
0X0
100
111
139 0 ▶ open my $fh, '<', "$proc/$pid/stat" or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", "$proc/$pid/stat" or return 0 0 0
140 0 ▶ my $text = do { local $/; <$fh> } // return;
Condition0%0/2
do { local $/; readline $fh } // (return)
l!l
00
MC/DC0%0/1
do { local $/; readline $fh } // (return)
do { local $/; readline $fh }
Truth table0%0/2
A
A= do { local $/; readline $fh }
Aresult
11
00
141 0 my ($l, $r) = (index($text, '('), rindex($text, ')'));
142 0 ▶ return if $l < 0 || $r < $l;
Branch: 1 branch
BranchTrueFalseTotal
if $l < 0 or $r < $l 0 0 0
Condition0%0/3
$l < 0 or $r < $l
l!l&&r!l&&!r
000
MC/DC0%0/2
$l < 0 or $r < $l
$l < 0 $r < $l
Truth table0%0/3
A or B
A= $l < 0B= $r < $l
ABresult
1X1
011
000
143 0 my @f = split ' ', substr $text, $r + 1;
144 0 ▶ return defined $f[19] && "@f[1, 19]" =~ /\A\d+ \d+\z/ ? (@f[0, 1, 19], substr $text, $l + 1, $r - $l - 1) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $f[19] && join($", @f[1, 19]) =~ /\A\d+ \d+\z/u ? : 0 0 0
Condition0%0/3
defined $f[19] and join($", @f[1, 19]) =~ /\A\d+ \d+\z/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $f[19] and join($", @f[1, 19]) =~ /\A\d+ \d+\z/u
defined $f[19] join($", @f[1, 19]) =~ /\A\d+ \d+\z/u
Truth table0%0/3
A and B
A= defined $f[19]B= join($", @f[1, 19]) =~ /\A\d+ \d+\z/u
ABresult
0X0
100
111
145 }
146  
147 0 ▶sub starttime ($pid, $proc = '/proc') {
Subroutine starttime: not called CC=2 SCAR=17.9
Pod documented
148 0 my (undef, undef, $start) = _stat($pid, $proc);
149 0 return $start;
150 }
151  
152 0 ▶sub _alive ($pid) {
Subroutine _alive: not called CC=3 SCAR=24.8
153 0 my ($state, undef, $start) = _stat($pid);
154 0 ▶ return defined $start && $state !~ /\A[ZX]/ ? $start : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $start && !($state =~ /\A[ZX]/u) ? : 0 0 0
Condition0%0/3
defined $start and not $state =~ /\A[ZX]/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $start and not $state =~ /\A[ZX]/u
defined $start not $state =~ /\A[ZX]/u
Truth table0%0/3
A and not(B)
A= defined $startB= not $state =~ /\A[ZX]/u
ABresult
0X0
100
111
155 }
156  
157 0 ▶sub _under ($pid) {
Subroutine _under: not called CC=8 SCAR=42.8
158 0 ▶ return 0 unless defined $pid && $pid =~ /\A[1-9]\d*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid and $pid =~ /\A[1-9]\d*\z/u 0 0 0
Condition0%0/3
defined $pid and $pid =~ /\A[1-9]\d*\z/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pid and $pid =~ /\A[1-9]\d*\z/u
defined $pid $pid =~ /\A[1-9]\d*\z/u
Truth table0%0/3
A and B
A= defined $pidB= $pid =~ /\A[1-9]\d*\z/u
ABresult
0X0
100
111
159 0 ▶ my (undef, $parent) = _stat($$) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my(undef, $parent) = _stat($$) or return 0 0 0 0
160 0 ▶ return 1 if $parent == $pid;
Branch: 1 branch
BranchTrueFalseTotal
if $parent == $pid 0 0 0
161 0 ▶ my (undef, $grand, undef, $comm) = _stat($parent) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my(undef, $grand, undef, $comm) = _stat($parent) or return 0 0 0 0
162 0 ▶ return $grand == $pid && $SHELL{$comm} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$grand == $pid && $SHELL{$comm} ? : 0 0 0
Condition0%0/3
$grand == $pid and $SHELL{$comm}
!ll&&!rl&&r
000
MC/DC0%0/2
$grand == $pid and $SHELL{$comm}
$grand == $pid $SHELL{$comm}
Truth table0%0/3
A and B
A= $grand == $pidB= $SHELL{$comm}
ABresult
0X0
100
111
163 }
164  
165 0 ▶sub _claude () {
Subroutine _claude: not called CC=4 SCAR=30.0
166 0 ▶ my $entry = $ENV{CLAUDE_CODE_ENTRYPOINT} // '';
Condition0%0/2
$ENV{"CLAUDE_CODE_ENTRYPOINT"} // ""
l!l
00
MC/DC0%0/1
$ENV{"CLAUDE_CODE_ENTRYPOINT"} // ""
$ENV{"CLAUDE_CODE_ENTRYPOINT"}
Truth table0%0/2
A
A= $ENV{"CLAUDE_CODE_ENTRYPOINT"}
Aresult
11
00
167 0 ▶ return ($entry eq 'cli' || $entry eq 'sdk-cli') && _under($ENV{CLAUDE_PID});
Condition0%0/6
($entry eq 'cli' || $entry eq 'sdk-cli') && _under($ENV{'CLAUDE_PID'})
!ll&&!rl&&r
000
$entry eq "cli" or $entry eq "sdk-cli"
l!l&&r!l&&!r
000
MC/DC0%0/3
($entry eq 'cli' || $entry eq 'sdk-cli') && _under($ENV{'CLAUDE_PID'})
$entry eq "cli" $entry eq "sdk-cli" _under($ENV{'CLAUDE_PID'})
Truth table0%0/5
A or B && C
A= $entry eq "cli"B= $entry eq "sdk-cli"C= _under($ENV{'CLAUDE_PID'})
ABCresult
00X0
1X00
0100
1X11
0111
168 }
169  
170 0 ▶sub _knob ($name, $default) {
Subroutine _knob: not called CC=4 SCAR=30.0
171 0 my $v = $ENV{$name};
172 0 ▶ return defined $v && $v =~ /\A\d+(?:\.\d+)?\z/ && $v > 0 ? $v : $default;
Branch: 1 branch
BranchTrueFalseTotal
defined $v && $v =~ /\A\d+(?:\.\d+)?\z/u && $v > 0 ? : 0 0 0
Condition0%0/6
defined $v and $v =~ /\A\d+(?:\.\d+)?\z/u and $v > 0
!ll&&!rl&&r
000
defined $v and $v =~ /\A\d+(?:\.\d+)?\z/u
!ll&&!rl&&r
000
MC/DC0%0/3
defined $v and $v =~ /\A\d+(?:\.\d+)?\z/u and $v > 0
defined $v $v =~ /\A\d+(?:\.\d+)?\z/u $v > 0
Truth table0%0/4
A and B and C
A= defined $vB= $v =~ /\A\d+(?:\.\d+)?\z/uC= $v > 0
ABCresult
0XX0
10X0
1100
1111
173 }
174  
175 0 ▶sub _reset ($session, $until) {
Subroutine _reset: not called CC=1 SCAR=6.9
176 0 eval {
177 0 ▶ _locked($session, $until, sub ($path) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
178 0 my ($seq, $epoch) = _read($path);
179 0 ▶ return unless $seq;
Branch: 1 branch
BranchTrueFalseTotal
unless $seq 0 0 0
180 0 ▶ my $tmp = _stage($path, "0 $epoch\n") // return;
Condition0%0/2
_stage($path, "0 $epoch\n") // (return)
l!l
00
MC/DC0%0/1
_stage($path, "0 $epoch\n") // (return)
_stage($path, "0 $epoch\n")
Truth table0%0/2
A
A= _stage($path, "0 $epoch\n")
Aresult
11
00
181 0 ▶ rename $tmp, $path or unlink $tmp;
Branch: 1 branch
BranchTrueFalseTotal
rename $tmp, $path or unlink $tmp 0 0 0
182 0 });
183 };
184 }
185  
186 0 ▶sub _stop_waiter ($session, $until) {
Subroutine _stop_waiter: not called CC=14 SCAR=53.5
187 0 ▶ sysopen my $fh, App::teai::Config::runtime_dir() . "/$session.waiter", O_RDONLY or return;
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $fh, App::teai::Config::runtime_dir() . "/$session.waiter", 0 or return 0 0 0
188 0 my %sent;
189 0 ▶ until (flock $fh, LOCK_EX | LOCK_NB) {
Branch: 1 branch
BranchTrueFalseTotal
unless (flock $fh, 6) 0 0 0
190 0 ▶ if (App::teai::Bus::now() >= $until) {
Branch: 1 branch
BranchTrueFalseTotal
if (App::teai::Bus::now() >= $until) 0 0 0
191 0 ▶ kill 'KILL', $_ for grep { (_alive($_) // '') eq $sent{$_} } keys %sent;
Condition0%0/2
_alive($_) // ""
l!l
00
MC/DC0%0/1
_alive($_) // ""
_alive($_)
Truth table0%0/2
A
A= _alive($_)
Aresult
11
00
192 0 return;
193 }
194 0 my $line = '';
195 0 sysseek $fh, 0, 0;
196 0 sysread $fh, $line, 64;
197 0 my ($pid, $start) = $line =~ /\A([1-9]\d*) (\d+)\n/;
198 $sent{$pid} = $start
199 0 ▶ if $pid && !exists $sent{$pid} && $pid != $$ && $pid ne ($ENV{CLAUDE_PID} // '')
Branch: 1 branch
BranchTrueFalseTotal
if $pid and not exists $sent{$pid} and $pid != $$ and $pid ne ($ENV{"CLAUDE_PID"} // "") and (starttime($pid) // "") eq $start and kill "TERM", $pid 0 0 0
Condition0%0/19
$pid and not exists $sent{$pid} and $pid != $$ and $pid ne ($ENV{"CLAUDE_PID"} // "") and (starttime($pid) // "") eq $start and kill "TERM", $pid
!ll&&!rl&&r
000
$pid and not exists $sent{$pid} and $pid != $$ and $pid ne ($ENV{"CLAUDE_PID"} // "") and (starttime($pid) // "") eq $start
!ll&&!rl&&r
000
$pid and not exists $sent{$pid} and $pid != $$ and $pid ne ($ENV{"CLAUDE_PID"} // "")
!ll&&!rl&&r
000
$pid and not exists $sent{$pid} and $pid != $$
!ll&&!rl&&r
000
$pid and not exists $sent{$pid}
!ll&&!rl&&r
000
$ENV{"CLAUDE_PID"} // ""
l!l
00
starttime($pid) // ""
l!l
00
MC/DC0%0/6
$pid and not exists $sent{$pid} and $pid != $$ and $pid ne ($ENV{"CLAUDE_PID"} // "") and (starttime($pid) // "") eq $start and kill "TERM", $pid
$pid not exists $sent{$pid} $pid != $$ $pid ne ($ENV{"CLAUDE_PID"} // "") starttime($pid) kill "TERM", $pid
MC/DC0%0/1
$ENV{"CLAUDE_PID"} // ""
$ENV{"CLAUDE_PID"}
Truth table0%0/7
A and not(B) and C and D and E and F
A= $pidB= not exists $sent{$pid}C= $pid != $$D= $pid ne ($ENV{"CLAUDE_PID"} // "")E= starttime($pid)F= kill "TERM", $pid
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
Truth table0%0/2
A
A= $ENV{"CLAUDE_PID"}
Aresult
11
00
200 && (starttime($pid) // '') eq $start && kill 'TERM', $pid;
201 0 Time::HiRes::sleep($LOCK_RETRY);
202 }
203 }
204  
205 0 ▶sub _watch ($session, $cfg, %o) {
Subroutine _watch: not called CC=1 SCAR=6.9
206 0 my $settle = _knob('TEAI_TEST_WAKE_SETTLE', $SETTLE);
207 0 my ($connecting, $bus, $probing, $settling, %memo) = (0);
208 0 ▶ my $wake = sub ($r, $e = undef) {
Subroutine __ANON__: not called CC=6 SCAR=37.4
209 0 undef $settling;
210 0 ▶ return $o{removed}->() if $r && $r->{removed};
Branch: 1 branch
BranchTrueFalseTotal
if $r and $r->{"removed"} 0 0 0
Condition0%0/3
$r and $r->{"removed"}
!ll&&!rl&&r
000
MC/DC0%0/2
$r and $r->{"removed"}
$r $r->{"removed"}
Truth table0%0/3
A and B
A= $rB= $r->{"removed"}
ABresult
0X0
100
111
211 0 ▶ $o{wake}->($r) if $r && $r->{pending};
Branch: 1 branch
BranchTrueFalseTotal
if $r and $r->{"pending"} 0 0 0
Condition0%0/3
$r and $r->{"pending"}
!ll&&!rl&&r
000
MC/DC0%0/2
$r and $r->{"pending"}
$r $r->{"pending"}
Truth table0%0/3
A and B
A= $rB= $r->{"pending"}
ABresult
0X0
100
111
212 0 };
213 0 ▶ my $look = sub ($r, $e = undef) {
Subroutine __ANON__: not called CC=10 SCAR=47.0
214 0 $probing = 0;
215 0 ▶ return $o{removed}->() if $r && $r->{removed};
Branch: 1 branch
BranchTrueFalseTotal
if $r and $r->{"removed"} 0 0 0
Condition0%0/3
$r and $r->{"removed"}
!ll&&!rl&&r
000
MC/DC0%0/2
$r and $r->{"removed"}
$r $r->{"removed"}
Truth table0%0/3
A and B
A= $rB= $r->{"removed"}
ABresult
0X0
100
111
216 0 ▶ return unless $r && $r->{pending};
Branch: 1 branch
BranchTrueFalseTotal
unless $r and $r->{"pending"} 0 0 0
Condition0%0/3
$r and $r->{"pending"}
!ll&&!rl&&r
000
MC/DC0%0/2
$r and $r->{"pending"}
$r $r->{"pending"}
Truth table0%0/3
A and B
A= $rB= $r->{"pending"}
ABresult
0X0
100
111
217 0 ▶ my ($seq, $epoch) = eval { _locked($session, App::teai::Bus::now() + $TICK_LOCK, \&_read) } or return;
Branch: 1 branch
BranchTrueFalseTotal
() = eval { do { _locked($session, App::teai::Bus::now() + $TICK_LOCK, \&App::teai::Hook::_read) } } or return 0 0 0
218 0 ▶ return unless _due($r, $seq) && (!$o{ready} || $o{ready}->($epoch));
Branch: 1 branch
BranchTrueFalseTotal
unless _due($r, $seq) and !$o{"ready"} || $o{"ready"}->($epoch) 0 0 0
Condition0%0/6
_due($r, $seq) and !$o{"ready"} || $o{"ready"}->($epoch)
!ll&&!rl&&r
000
not $o{"ready"} or $o{"ready"}->($epoch)
l!l&&r!l&&!r
000
MC/DC0%0/3
_due($r, $seq) and !$o{"ready"} || $o{"ready"}->($epoch)
_due($r, $seq) not $o{"ready"} $o{"ready"}->($epoch)
Truth table0%0/4
A and not(B) or C
A= _due($r, $seq)B= not $o{"ready"}C= $o{"ready"}->($epoch)
ABCresult
0XX0
1000
11X1
1011
219 0 ▶ $settling = EV::timer $settle, 0, sub { probe($bus, $session, $wake) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
220 0 };
221 0 ▶ my $tick = EV::timer 0, _knob('TEAI_TEST_WAKE_POLL', $POLL), sub {
Subroutine __ANON__: not called CC=12 SCAR=50.5
222 0 ▶ return if $o{tick} && !$o{tick}->();
Branch: 1 branch
BranchTrueFalseTotal
if $o{"tick"} and not $o{"tick"}->() 0 0 0
Condition0%0/3
$o{"tick"} and not $o{"tick"}->()
!ll&&!rl&&r
000
MC/DC0%0/2
$o{"tick"} and not $o{"tick"}->()
$o{"tick"} not $o{"tick"}->()
Truth table0%0/3
A and not(B)
A= $o{"tick"}B= not $o{"tick"}->()
ABresult
0X0
100
111
223 0 ▶ my $refusal = $bus && $bus->refused_link;
Condition0%0/3
$bus && $bus->refused_link
!ll&&!rl&&r
000
MC/DC0%0/2
$bus && $bus->refused_link
$bus $bus->refused_link
Truth table0%0/3
A && B
A= $busB= $bus->refused_link
ABresult
0X0
100
111
224 0 ▶ return $o{refused}->($refusal) if defined $refusal;
Branch: 1 branch
BranchTrueFalseTotal
if defined $refusal 0 0 0
225 0 ▶ return if $connecting || $probing || $settling;
Branch: 1 branch
BranchTrueFalseTotal
if $connecting or $probing or $settling 0 0 0
Condition0%0/6
$connecting or $probing or $settling
l!l&&r!l&&!r
000
$connecting or $probing
l!l&&r!l&&!r
000
MC/DC0%0/3
$connecting or $probing or $settling
$connecting $probing $settling
Truth table0%0/4
A or B or C
A= $connectingB= $probingC= $settling
ABCresult
1XX1
01X1
0011
0000
226 0 ▶ unless ($bus) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bus) 0 0 0
227 0 $connecting = 1;
228 0 $bus = eval { App::teai::Bus->new(%$cfg, reconnect => 1) };
229 0 $connecting = 0;
230 0 ▶ return $o{failed} && $o{failed}->($@) unless $bus;
Branch: 1 branch
BranchTrueFalseTotal
unless $bus 0 0 0
Condition0%0/3
$o{'failed'} && $o{'failed'}->($@)
!ll&&!rl&&r
000
MC/DC0%0/2
$o{'failed'} && $o{'failed'}->($@)
$o{'failed'} $o{'failed'}->($@)
Truth table0%0/3
A && B
A= $o{'failed'}B= $o{'failed'}->($@)
ABresult
0X0
100
111
231 }
232 0 ▶ return unless $bus->nats->is_connected;
Branch: 1 branch
BranchTrueFalseTotal
unless $bus->nats->is_connected 0 0 0
233 0 $probing = 1;
234 0 probe($bus, $session, $look, \%memo);
235 0 };
236 0 ▶ return { tick => $tick, connecting => \$connecting, bus => sub { $bus } };
Subroutine __ANON__: not called CC=1 SCAR=6.9
237 }
238  
239 0 ▶sub _wait ($session) {
Subroutine _wait: not called CC=13 SCAR=52.0
240 0 ▶ return 0 unless ($ENV{CLAUDE_CODE_ENTRYPOINT} // '') eq 'cli';
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"CLAUDE_CODE_ENTRYPOINT"} // "") eq "cli" 0 0 0
Condition0%0/2
$ENV{"CLAUDE_CODE_ENTRYPOINT"} // ""
l!l
00
MC/DC0%0/1
$ENV{"CLAUDE_CODE_ENTRYPOINT"} // ""
$ENV{"CLAUDE_CODE_ENTRYPOINT"}
Truth table0%0/2
A
A= $ENV{"CLAUDE_CODE_ENTRYPOINT"}
Aresult
11
00
241 0 my $owner = $ENV{CLAUDE_PID};
242 0 ▶ my $born = _alive($owner) // return 0;
Condition0%0/2
_alive($owner) // (return 0)
l!l
00
MC/DC0%0/1
_alive($owner) // (return 0)
_alive($owner)
Truth table0%0/2
A
A= _alive($owner)
Aresult
11
00
243 0 ▶ _under($owner) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
_under($owner) or return 0 0 0 0
244 0 ▶ my $me = starttime($$) // return 0;
Condition0%0/2
starttime($$) // (return 0)
l!l
00
MC/DC0%0/1
starttime($$) // (return 0)
starttime($$)
Truth table0%0/2
A
A= starttime($$)
Aresult
11
00
245 0 ▶ my $cfg = eval { App::teai::Config::load() } or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $cfg = eval { do { App::teai::Config::load() } } or return 0 0 0 0
246 0 my $interval = _knob('TEAI_TEST_WAKE_INTERVAL', $INTERVAL);
247 0 ▶ sysopen my $lock, App::teai::Config::runtime_dir() . "/$session.waiter", O_RDWR | O_CREAT, 0600 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $lock, App::teai::Config::runtime_dir() . "/$session.waiter", 66, 384 or return 0 0 0 0
248 0 ▶ flock $lock, LOCK_EX | LOCK_NB or return 0;
Branch: 1 branch
BranchTrueFalseTotal
flock $lock, 6 or return 0 0 0 0
249 0 my $line = "$$ $me\n";
250 0 ▶ truncate $lock, 0 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
truncate $lock, 0 or return 0 0 0 0
251 0 ▶ (syswrite($lock, $line) // 0) == length $line or return 0;
Branch: 1 branch
BranchTrueFalseTotal
(syswrite($lock, $line) // 0) == length $line or return 0 0 0 0
Condition0%0/2
syswrite($lock, $line) // 0
l!l
00
MC/DC0%0/1
syswrite($lock, $line) // 0
syswrite($lock, $line)
Truth table0%0/2
A
A= syswrite($lock, $line)
Aresult
11
00
252 0 Time::HiRes::alarm(0);
253 0 my ($rc, $w);
254 0 ▶ my $quit = sub { $rc //= 0; POSIX::_exit(0) if $w && ${ $w->{connecting} } };
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if $w and ${$w->{"connecting"};} 0 0 0
Condition0%0/5
$rc //= 0
l!l
00
$w and ${$w->{"connecting"};}
!ll&&!rl&&r
000
MC/DC0%0/1
$rc //= 0
$rc
MC/DC0%0/2
$w and ${$w->{"connecting"};}
$w ${$w->{"connecting"};}
Truth table0%0/2
A
A= $rc
Aresult
11
00
Truth table0%0/3
A and B
A= $wB= ${$w->{"connecting"};}
ABresult
0X0
100
111
255 0 local $EV::DIED = $quit;
256 0 ▶ my $owned = sub { (_alive($owner) // '') eq $born };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
_alive($owner) // ""
l!l
00
MC/DC0%0/1
_alive($owner) // ""
_alive($owner)
Truth table0%0/2
A
A= _alive($owner)
Aresult
11
00
257 $w = _watch($session, $cfg,
258 0 ▶ tick => sub { return 1 if $owned->(); $quit->(); return 0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if &$owned() 0 0 0
259 0 ▶ ready => sub ($epoch) { abs(Time::HiRes::time() - $epoch) >= $interval },
Subroutine __ANON__: not called CC=1 SCAR=6.9
260 0 ▶ failed => sub ($e) { $quit->() if App::teai::Bus::refused($e) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if App::teai::Bus::refused($e) 0 0 0
261 removed => $quit,
262 refused => $quit,
263 0 ▶ wake => sub ($r) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
264 0 ▶ return $quit->() unless $owned->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$owned() 0 0 0
265 0 $HOLD = 1;
266 0 my $done = announce($session, $r, \*STDERR, Time::HiRes::time(), App::teai::Bus::now() + $TICK_LOCK);
267 # from here to the exit a stop is only noted, so a moved cursor always ends with 2
268 0 ▶ if ($done) { $rc = $done > 0 ? 2 : 0 }
Branch: 2 branches
BranchTrueFalseTotal
if ($done) { } 0 0 0
$done > 0 ? : 0 0 0
269 0 else { _release() }
270 },
271 0 );
272 0 ▶ my $presence = App::teai::Presence->new(kind => 'waiter', session => $session, bus => sub { $w->{bus}->() });
Subroutine __ANON__: not called CC=1 SCAR=6.9
273 0 ▶ EV::run(EV::RUN_ONCE) until defined $rc;
Branch: 1 branch
BranchTrueFalseTotal
defined $rc or do { &EV::run(2) } 0 0 0
274 0 $presence->stop;
275 0 POSIX::_exit($rc);
276 }
277  
278 0 ▶sub watch (%o) {
Subroutine watch: not called CC=5 SCAR=34.0
Pod documented
279 0 ▶ my ($session, $out) = ($o{session}, $o{out} // \*STDOUT);
Condition0%0/2
$o{"out"} // \*STDOUT
l!l
00
MC/DC0%0/1
$o{"out"} // \*STDOUT
$o{"out"}
Truth table0%0/2
A
A= $o{"out"}
Aresult
11
00
280 0 my ($rc, $why, $told) = (undef, undef, 0);
281 0 local @SIG{qw(INT TERM HUP)} = @SIG{qw(INT TERM HUP)};
282 0 _catch();
283 0 ▶ local $EV::DIED = sub { ($rc, $why) = (3, App::teai::Bus::_text($@)) unless defined $rc };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rc 0 0 0
284 my $w = _watch($session, $o{config},
285 0 ▶ failed => sub ($e) { ($rc, $why) = (3, App::teai::Bus::_text($e)) if App::teai::Bus::refused($e) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if App::teai::Bus::refused($e) 0 0 0
286 0 ▶ removed => sub { ($rc, $why) = (2, App::teai::Bus::_text(App::teai::Bus::removed_err($session))) unless defined $rc },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rc 0 0 0
287 0 ▶ refused => sub ($text) { ($rc, $why) = (3, "not connected (server: $text)") unless defined $rc },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rc 0 0 0
288 0 ▶ wake => sub ($r) {
Subroutine __ANON__: not called CC=6 SCAR=37.4
289 0 $HOLD = 1;
290 0 my $done = announce($session, $r, $out, undef, App::teai::Bus::now() + $TICK_LOCK);
291 0 ▶ ($rc, $why) = (3, "write failed: $!") if $done == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $done == -1 0 0 0
292 0 ▶ if ($done > 0 || $done == -2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done > 0 or $done == -2) 0 0 0
Condition0%0/3
$done > 0 or $done == -2
l!l&&r!l&&!r
000
MC/DC0%0/2
$done > 0 or $done == -2
$done > 0 $done == -2
Truth table0%0/3
A or B
A= $done > 0B= $done == -2
ABresult
1X1
011
000
293 0 $told++;
294 0 ▶ $rc = 0 if !$o{follow} || $done == -2;
Branch: 1 branch
BranchTrueFalseTotal
if not $o{"follow"} or $done == -2 0 0 0
Condition0%0/3
not $o{"follow"} or $done == -2
l!l&&r!l&&!r
000
MC/DC0%0/2
not $o{"follow"} or $done == -2
not $o{"follow"} $done == -2
Truth table0%0/3
not(A) or B
A= not $o{"follow"}B= $done == -2
ABresult
1X1
011
000
295 }
296 0 _release();
297 },
298 0 );
299 0 ▶ my $presence = App::teai::Presence->new(kind => 'wait', session => $session, bus => sub { $w->{bus}->() });
Subroutine __ANON__: not called CC=1 SCAR=6.9
300 0 EV::now_update();
301 0 ▶ my $limit = $o{timeout} ? EV::timer($o{timeout}, 0, sub { POSIX::_exit($told ? 0 : 1) }) : undef;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
$o{'timeout'} ? : 0 0 0
$told ? : 0 0 0
302 0 ▶ EV::run(EV::RUN_ONCE) until defined $rc;
Branch: 1 branch
BranchTrueFalseTotal
defined $rc or do { &EV::run(2) } 0 0 0
303 0 undef $limit;
304 0 $presence->stop;
305 0 ▶ App::teai::Err::fail($rc, $why) if $rc;
Branch: 1 branch
BranchTrueFalseTotal
if $rc 0 0 0
306 0 return 0;
307 }
308  
309 0 ▶sub _slurp ($fh) {
Subroutine _slurp: not called CC=6 SCAR=37.4
310 0 my $buf = '';
311 0 ▶ while (length $buf <= $MAX_STDIN) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $buf <= $MAX_STDIN) 0 0 0
312 0 my $n = sysread $fh, $buf, 65536, length $buf;
313 0 ▶ next if !defined $n && $!{EINTR};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $n and $!{"EINTR"} 0 0 0
Condition0%0/3
not defined $n and $!{"EINTR"}
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $n and $!{"EINTR"}
not defined $n $!{"EINTR"}
Truth table0%0/3
not(A) and B
A= not defined $nB= $!{"EINTR"}
ABresult
0X0
100
111
314 0 ▶ return undef unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 0 0
315 0 ▶ last unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 0 0
316 }
317 0 return $buf;
318 }
319  
320 0 ▶sub _event ($in) {
Subroutine _event: not called CC=5 SCAR=34.0
321 0 ▶ my $bytes = ref $in ? _slurp($in) : $in;
Branch: 1 branch
BranchTrueFalseTotal
ref $in ? : 0 0 0
322 0 ▶ return {} if !defined $bytes || length $bytes > $MAX_STDIN;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $bytes or length $bytes > $MAX_STDIN 0 0 0
Condition0%0/3
not defined $bytes or length $bytes > $MAX_STDIN
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $bytes or length $bytes > $MAX_STDIN
not defined $bytes length $bytes > $MAX_STDIN
Truth table0%0/3
not(A) or B
A= not defined $bytesB= length $bytes > $MAX_STDIN
ABresult
1X1
011
000
323 0 my $ev = eval { Cpanel::JSON::XS->new->utf8->decode($bytes) };
324 0 ▶ return ref $ev eq 'HASH' ? $ev : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ev eq 'HASH' ? : 0 0 0
325 }
326  
327 0 ▶sub _prompt ($session, $until) {
Subroutine _prompt: not called CC=2 SCAR=17.9
328 0 ▶ return 0 unless _claude();
Branch: 1 branch
BranchTrueFalseTotal
unless _claude() 0 0 0
329 0 eval {
330 0 ▶ _locked($session, $until, sub ($path) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
331 0 my $stop = App::teai::Bus::now() + _knob('TEAI_TEST_STOP_WAIT', $STOP_WAIT);
332 0 ▶ _stop_waiter($session, $stop < $until ? $stop : $until);
Branch: 1 branch
BranchTrueFalseTotal
$stop < $until ? : 0 0 0
333 0 my $bus = App::teai::Bus->new(%{ App::teai::Config::load() }, reconnect => 0);
334 0 my ($res, $over);
335 0 my $left = $until - App::teai::Bus::now();
336 0 ▶ my $guard = EV::timer $left > 0 ? $left : 0, 0, sub { $over = 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$left > 0 ? : 0 0 0
337 0 ▶ probe($bus, $session, sub ($r, $e = undef) { ($res, $over) = ($r, 1) });
Subroutine __ANON__: not called CC=2 SCAR=17.9
338 0 ▶ EV::run(EV::RUN_ONCE) until $over;
Branch: 1 branch
BranchTrueFalseTotal
$over or do { &EV::run(2) } 0 0 0
339 0 _commit($path, $res, \*STDOUT);
340 0 });
341 };
342 0 return 0;
343 }
344  
345 0 ▶sub _run ($o) {
Subroutine _run: not called CC=12 SCAR=50.5
346 0 ▶ my $env = $o->{env} // {};
Condition0%0/2
$o->{"env"} // {}
l!l
00
MC/DC0%0/1
$o->{"env"} // {}
$o->{"env"}
Truth table0%0/2
A
A= $o->{"env"}
Aresult
11
00
347 0 my $session = $env->{TEAI_SESSION};
348 0 ▶ return 0 unless App::teai::Wire::valid_id($session);
Branch: 1 branch
BranchTrueFalseTotal
unless App::teai::Wire::valid_id($session) 0 0 0
349 0 local %ENV = %$env;
350 0 _catch();
351 0 ▶ POSIX::sigaction(POSIX::SIGALRM(), POSIX::SigAction->new(sub { POSIX::_exit(0) }));
Subroutine __ANON__: not called CC=1 SCAR=6.9
352 0 my $bound = _knob('TEAI_TEST_HOOK_BOUND', $BOUND);
353 0 Time::HiRes::alarm($bound);
354 0 my $until = App::teai::Bus::now() + $bound - ($BOUND - $FAST_BOUND);
355 0 my $ev = _event($o->{stdin});
356 0 ▶ my $name = $ev->{hook_event_name} // '';
Condition0%0/2
$ev->{"hook_event_name"} // ""
l!l
00
MC/DC0%0/1
$ev->{"hook_event_name"} // ""
$ev->{"hook_event_name"}
Truth table0%0/2
A
A= $ev->{"hook_event_name"}
Aresult
11
00
357 0 ▶ if ($o->{reset}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"reset"}) 0 0 0
358 0 ▶ _reset($session, $until) if $name eq 'SessionStart' && $NEW_CONTEXT{ $ev->{source} // '' } && _claude();
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "SessionStart" and $NEW_CONTEXT{$ev->{"source"} // ""} and _claude() 0 0 0
Condition0%0/8
$name eq "SessionStart" and $NEW_CONTEXT{$ev->{"source"} // ""} and _claude()
!ll&&!rl&&r
000
$name eq "SessionStart" and $NEW_CONTEXT{$ev->{"source"} // ""}
!ll&&!rl&&r
000
$ev->{"source"} // ""
l!l
00
MC/DC0%0/3
$name eq "SessionStart" and $NEW_CONTEXT{$ev->{"source"} // ""} and _claude()
$name eq "SessionStart" $NEW_CONTEXT{$ev->{"source"} // ""} _claude()
MC/DC0%0/1
$ev->{"source"} // ""
$ev->{"source"}
Truth table0%0/4
A and B and C
A= $name eq "SessionStart"B= $NEW_CONTEXT{$ev->{"source"} // ""}C= _claude()
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/2
A
A= $ev->{"source"}
Aresult
11
00
359 0 return 0;
360 }
361 0 ▶ return _prompt($session, $until) if $name eq 'UserPromptSubmit';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "UserPromptSubmit" 0 0 0
362 0 ▶ return 0 unless $name eq 'Stop' || $name eq 'SessionStart';
Branch: 1 branch
BranchTrueFalseTotal
unless $name eq "Stop" or $name eq "SessionStart" 0 0 0
Condition0%0/3
$name eq "Stop" or $name eq "SessionStart"
l!l&&r!l&&!r
000
MC/DC0%0/2
$name eq "Stop" or $name eq "SessionStart"
$name eq "Stop" $name eq "SessionStart"
Truth table0%0/3
A or B
A= $name eq "Stop"B= $name eq "SessionStart"
ABresult
1X1
011
000
363 0 return _wait($session);
364 }
365  
366 0 ▶sub run (%o) {
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
367 0 ▶ local $SIG{__WARN__} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
368 0 local $SIG{PIPE} = 'IGNORE';
369 0 local @SIG{qw(ALRM INT TERM HUP)} = @SIG{qw(ALRM INT TERM HUP)};
370 0 ▶ my $rc = eval { _run(\%o) } // 0;
Condition0%0/2
eval { do { _run(\%o) } } // 0
l!l
00
MC/DC0%0/1
eval { do { _run(\%o) } } // 0
eval { do { _run(\%o) } }
Truth table0%0/2
A
A= eval { do { _run(\%o) } }
Aresult
11
00
371 0 Time::HiRes::alarm(0);
372 0 return $rc;
373 }
374  
375 1 1;
376 __END__
« lib/App/teai/Dash/Rounds.pm ↑ Summary lib/App/teai/Dash.pm »