blib/lib/Langertha/Holmgang/Report.pm

filter: Statementstmt 99.7% 395 / 396 Branchbran 83.7% 186 / 222 Conditioncond 68.4% 100 / 146 MC/DCmcdc 45.0% 36 / 80 Subroutinesub 100% 39 / 39 Podpod 84.6% 11 / 13 totaltotal 85.6% 767 / 896 CC 187 SCAR 30.3
CC
187
Cov
89%
_shape
43.0
from_cai_platform
30.6
_cai_repetition
28.8
CRAP 20.8
« blib/lib/Langertha/Holmgang/Batch.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/RouterOS.pm »
1 package Langertha::Holmgang::Report;
2 # ABSTRACT: The JSON report of a Holmgang invocation, format holmgang_report 1
3  
4 27 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 27 ▶use Digest::SHA qw( sha256_hex );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 27 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 27 ▶use Langertha ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 27 ▶use Langertha::Holmgang ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use POSIX qw( strftime );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 27 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 27 ▶use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 27 our $VERSION = '0.001';
17  
18 #### Format
19  
20 # The format version this module writes and the highest it reads (ADR 0006).
21 105 ▶sub format_version { 1 }
Subroutine format_version: called CC=1 SCAR=0.0
Pod undocumented
22  
23 # The shape of format 1. A field spec is a primitive name (int num str bool
24 # time url any), the name of an entry of this table, or a hash with `type`
25 # and optional `null => 0` (never null), `min`, `max`, `of` (array element)
26 # or `values` (enum). Every field may be null unless it says `null => 0`;
27 # array elements are never null. `optional => 1` marks a field added after
28 # version 1 came out: a reader takes it as null where an older report lacks it.
29 27 my %SPEC = (
30 report => { type => 'object', fields => {
31 holmgang_report => { type => 'int', null => 0 },
32 generator => 'generator',
33 started_at => 'time',
34 finished_at => 'time',
35 runs => { type => 'array', of => 'run', null => 0 },
36 } },
37 generator => { type => 'object', fields => {
38 holmgang => 'str',
39 langertha => 'str',
40 } },
41 run => { type => 'object', fields => {
42 target => 'target',
43 variant => 'variant',
44 suite => 'suite',
45 repeat => { type => 'int', min => 1, null => 0 },
46 status => { type => 'enum', values => [qw( complete cancelled aborted )], null => 0 },
47 error => 'str',
48 cases => { type => 'array', of => 'case', null => 0 },
49 } },
50 target => { type => 'object', null => 0, fields => {
51 label => 'str',
52 engine => 'str',
53 model => 'str',
54 url => 'url',
55 } },
56 variant => { type => 'object', null => 0, fields => {
57 name => 'str',
58 settings => 'any',
59 } },
60 suite => { type => 'object', null => 0, fields => {
61 id => { type => 'str', null => 0 },
62 version => 'str',
63 topic => 'str',
64 digest => 'str',
65 } },
66 case => { type => 'object', fields => {
67 case_id => { type => 'str', null => 0 },
68 title => 'str',
69 tags => { type => 'array', of => 'str' },
70 tier => 'str',
71 difficulty => { type => 'str', optional => 1 },
72 weight => { type => 'num', min => 0 },
73 hard => 'bool',
74 untrusted => 'bool',
75 repetitions => { type => 'array', of => 'repetition', null => 0 },
76 } },
77 repetition => { type => 'object', fields => {
78 repetition => { type => 'int', min => 1, null => 0 },
79 seed => 'int',
80 status => { type => 'enum', values => [qw(
81 no_vision context_exceeded error turn_limit passed uncertain failed
82 )], null => 0 },
83 score => { type => 'num', min => 0, max => 1 },
84 error => 'str',
85 finish_reason => 'str',
86 duration_ms => { type => 'int', min => 0 },
87 rules => { type => 'array', of => 'rule' },
88 diff => { type => 'array', of => 'change' },
89 turns => { type => 'array', of => 'turn' },
90 tokens => 'tokens',
91 calls => { type => 'array', of => 'call' },
92 sim_gaps => { type => 'array', of => 'gap' },
93 forbidden_calls => { type => 'int', min => 0 },
94 injection_held => 'bool',
95 transcript => { type => 'array', of => 'any' },
96 } },
97 rule => { type => 'object', fields => {
98 title => 'str',
99 kind => 'str',
100 required => 'bool',
101 passed => 'bool',
102 reason => 'str',
103 sim_gap => 'str',
104 } },
105 change => { type => 'object', fields => {
106 path => 'str',
107 before => 'any',
108 after => 'any',
109 } },
110 turn => { type => 'object', fields => {
111 input_tokens => { type => 'int', min => 0 },
112 output_tokens => { type => 'int', min => 0 },
113 reasoning_tokens => { type => 'int', min => 0 },
114 duration_ms => { type => 'int', min => 0 },
115 finish_reason => 'str',
116 calls => { type => 'int', min => 0 },
117 } },
118 tokens => { type => 'object', null => 0, fields => {
119 input => { type => 'int', min => 0 },
120 output => { type => 'int', min => 0 },
121 reasoning => { type => 'int', min => 0 },
122 input_max => { type => 'int', min => 0 },
123 } },
124 call => { type => 'object', fields => {
125 tool => 'str',
126 args => 'any',
127 succeeded => 'bool',
128 sim_gap => 'str',
129 } },
130 gap => { type => 'object', fields => {
131 call => { type => 'int', min => 0 },
132 tool => 'str',
133 gap => 'str',
134 } },
135 );
136  
137 # Query parameters of a target url that carry credentials.
138 27 my $SECRET_PARAM = qr/key|token|secret|pass|auth|sig|cred/i;
139  
140 # Image content in any form a provider takes it.
141 27 my $DATA_URL = qr{\bdata:(?:image/|[^,\s]*;base64,)}i;
142 27 my $BASE64_RUN = qr{\A[A-Za-z0-9+/]{1024,}={0,2}\z};
143  
144 #### Attributes
145  
146 27 has generator => ( is => 'ro', lazy_build => 1 );
147  
148 159 ▶sub _build_generator {
Subroutine _build_generator: called CC=1 SCAR=0.0
149 return {
150 159 holmgang => $Langertha::Holmgang::VERSION,
151 langertha => $Langertha::VERSION,
152 };
153 }
154  
155  
156 27 has started_at => ( is => 'ro', lazy_build => 1 );
157  
158 81 ▶sub _build_started_at { shift->now }
Subroutine _build_started_at: called CC=1 SCAR=0.0
159  
160  
161 27 has finished_at => ( is => 'ro', writer => '_set_finished_at' );
162  
163  
164 27 has with_transcript => ( is => 'ro', default => 0 );
165  
166  
167 164 ▶has runs => ( is => 'ro', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
168  
169  
170 318 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=7.0
Pod undocumented
171 318 my ( $self ) = @_;
172 318 $self->generator;
173 318 $self->started_at;
174 318 my $runs = $self->runs;
175 318 ▶ croak __PACKAGE__.'->new runs must be an array' unless ref $runs eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $runs eq "ARRAY" 0 318 318
176 318 @$runs = map { $self->_shape( 'run', $runs->[$_], 'runs['.$_.']', 0 ) } 0 .. $#$runs;
177 318 return;
178 }
179  
180 #### Building
181  
182 131 ▶sub now {
Subroutine now: called CC=2 SCAR=7.2
Pod documented
183 131 my ( $self, $epoch ) = @_;
184 131 ▶ return strftime( '%Y-%m-%dT%H:%M:%SZ', gmtime( defined $epoch ? $epoch : time ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $epoch ? : 0 131 131
185 }
186  
187  
188 201 ▶sub add_run {
Subroutine add_run: called CC=19 SCAR=30.8
Pod documented
189 201 my ( $self, %arg ) = @_;
190 201 my $where = 'runs['.scalar( @{ $self->runs } ).']';
191 201 my $repeat = $arg{repeat};
192 201 ▶ my @cases = @{ $arg{cases} || croak __PACKAGE__.'->add_run needs cases' };
Condition50%1/2
$arg{'cases'} || croak('Langertha::Holmgang::Report->add_run needs cases')
l!l
2010
MC/DC0%0/1
$arg{'cases'} || croak('Langertha::Holmgang::Report->add_run needs cases')
$arg{'cases'}
Truth table50%1/2
A
A= $arg{'cases'}
Aresult
11
00
193 201 my ( %case, @order );
194 201 for my $i ( 0 .. $#cases ) {
195 366 my $c = $cases[$i];
196 croak __PACKAGE__.'->add_run '.$where.'.cases['.$i.'] has no case_id'
197 366 ▶ unless ref $c eq 'HASH' && defined $c->{case_id};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c eq "HASH" and defined $c->{"case_id"} 0 366 366
Condition33%1/3
ref $c eq "HASH" and defined $c->{"case_id"}
!ll&&!rl&&r
00366
MC/DC0%0/2
ref $c eq "HASH" and defined $c->{"case_id"}
ref $c eq "HASH" defined $c->{"case_id"}
Truth table33%1/3
A and B
A= ref $c eq "HASH"B= defined $c->{"case_id"}
ABresult
0X0
100
111
198 croak __PACKAGE__.'->add_run '.$where.': case '.$c->{case_id}.' listed twice'
199 366 ▶ if $case{ $c->{case_id} };
Branch: 1 branch
BranchTrueFalseTotal
if $case{$c->{"case_id"}} 0 366 366
200 366 $case{ $c->{case_id} } = { ( map { $_ => $c->{$_} } qw( case_id title tags tier difficulty weight hard untrusted ) ), repetitions => [] };
201 366 push @order, $c->{case_id};
202 }
203 201 my %seen;
204 201 ▶ for my $r ( @{ $arg{results} || [] } ) {
Condition100%2/2
$arg{'results'} || []
l!l
18912
MC/DC100%1/1
$arg{'results'} || []
$arg{'results'}
Truth table100%2/2
A
A= $arg{'results'}
Aresult
11
00
205 483 ▶ croak __PACKAGE__.'->add_run '.$where.': a result is not a hash' unless ref $r eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $r eq "HASH" 0 483 483
206 483 my $id = $r->{case_id};
207 croak __PACKAGE__.'->add_run '.$where.': result for unknown case '.( defined $id ? $id : '(none)' )
208 483 ▶ unless defined $id && $case{$id};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $id and $case{$id} 1 482 483
defined $id ? : 1 0 1
Condition66%2/3
defined $id and $case{$id}
!ll&&!rl&&r
01482
MC/DC50%1/2
defined $id and $case{$id}
defined $id $case{$id}
Truth table66%2/3
A and B
A= defined $idB= $case{$id}
ABresult
0X0
100
111
209 482 my $n = $r->{repetition};
210 482 ▶ croak __PACKAGE__.'->add_run '.$where.': case '.$id.' result without a repetition number'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n and $n =~ /\A[1-9][0-9]*\z/ 0 482 482
Condition33%1/3
defined $n and $n =~ /\A[1-9][0-9]*\z/
!ll&&!rl&&r
00482
MC/DC0%0/2
defined $n and $n =~ /\A[1-9][0-9]*\z/
defined $n $n =~ /\A[1-9][0-9]*\z/
Truth table33%1/3
A and B
A= defined $nB= $n =~ /\A[1-9][0-9]*\z/
ABresult
0X0
100
111
211 unless defined $n && $n =~ /\A[1-9][0-9]*\z/;
212 482 ▶ croak __PACKAGE__.'->add_run '.$where.': case '.$id.' repetition '.$n.' beyond repeat '.$repeat
Branch: 1 branch
BranchTrueFalseTotal
if defined $repeat and $repeat =~ /\A[0-9]+\z/ and $n > $repeat 1 481 482
Condition50%3/6
defined $repeat and $repeat =~ /\A[0-9]+\z/ and $n > $repeat
!ll&&!rl&&r
04811
defined $repeat and $repeat =~ /\A[0-9]+\z/
!ll&&!rl&&r
00482
MC/DC33%1/3
defined $repeat and $repeat =~ /\A[0-9]+\z/ and $n > $repeat
defined $repeat $repeat =~ /\A[0-9]+\z/ $n > $repeat
Truth table50%2/4
A and B and C
A= defined $repeatB= $repeat =~ /\A[0-9]+\z/C= $n > $repeat
ABCresult
0XX0
10X0
1100
1111
213 if defined $repeat && $repeat =~ /\A[0-9]+\z/ && $n > $repeat;
214 croak __PACKAGE__.'->add_run '.$where.': case '.$id.' repetition '.$n.' given twice'
215 481 ▶ if $seen{$id}{$n}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$id}{$n}++ 1 480 481
216 480 push @{ $case{$id}{repetitions} }, $self->_repetition( $r, $where.' case '.$id.' repetition '.$n );
217 }
218 196 for my $c ( values %case ) {
219 356 @{ $c->{repetitions} } = sort { $a->{repetition} <=> $b->{repetition} } @{ $c->{repetitions} };
220 }
221 my $run = $self->_shape( 'run', {
222 1176 ( map { $_ => $arg{$_} } qw( target variant suite repeat status error ) ),
223 196 cases => [ map { $case{$_} } @order ],
224 }, $where, 0 );
225 186 push @{ $self->runs }, $run;
226 186 return $run;
227 }
228  
229  
230 480 ▶sub _repetition {
Subroutine _repetition: called CC=12 SCAR=24.9
231 480 my ( $self, $r, $where ) = @_;
232 480 my $turns = $self->_shape( { type => 'array', of => 'turn' }, $r->{turns}, $where.'.turns', 0 );
233 479 my $calls = $self->_shape( { type => 'array', of => 'call' }, $r->{calls}, $where.'.calls', 0 );
234 478 my %tokens = map { $_ => undef } qw( input output reasoning input_max );
235 478 my ( $duration, $finish );
236 478 ▶ if ( $turns ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($turns) 472 6 478
237 472 $duration = 0;
238 472 for my $t ( @$turns ) {
239 356 ▶ $duration += $t->{duration_ms} if defined $t->{duration_ms};
Branch: 1 branch
BranchTrueFalseTotal
if defined $t->{"duration_ms"} 354 2 356
240 356 for my $f (qw( input output reasoning )) {
241 1068 my $v = $t->{ $f.'_tokens' };
242 1068 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 974 94 1068
243 94 ▶ $tokens{$f} = ( $tokens{$f} || 0 ) + $v;
Condition100%2/2
$tokens{$f} || 0
l!l
3856
MC/DC100%1/1
$tokens{$f} || 0
$tokens{$f}
Truth table100%2/2
A
A= $tokens{$f}
Aresult
11
00
244 }
245 $tokens{input_max} = $t->{input_tokens}
246 356 ▶ if defined $t->{input_tokens} && ( !defined $tokens{input_max} || $t->{input_tokens} > $tokens{input_max} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $t->{"input_tokens"} and !defined($tokens{"input_max"}) || $t->{"input_tokens"} > $tokens{"input_max"} 54 302 356
Condition66%4/6
defined $t->{"input_tokens"} and !defined($tokens{"input_max"}) || $t->{"input_tokens"} > $tokens{"input_max"}
!ll&&!rl&&r
302054
not defined $tokens{"input_max"} or $t->{"input_tokens"} > $tokens{"input_max"}
l!l&&r!l&&!r
35190
MC/DC33%1/3
defined $t->{"input_tokens"} and !defined($tokens{"input_max"}) || $t->{"input_tokens"} > $tokens{"input_max"}
defined $t->{"input_tokens"} not defined $tokens{"input_max"} $t->{"input_tokens"} > $tokens{"input_max"}
Truth table75%3/4
A and not(B) or C
A= defined $t->{"input_tokens"}B= not defined $tokens{"input_max"}C= $t->{"input_tokens"} > $tokens{"input_max"}
ABCresult
0XX0
1000
11X1
1011
247 }
248 472 ▶ $finish = $turns->[-1]{finish_reason} if @$turns;
Branch: 1 branch
BranchTrueFalseTotal
if @$turns 202 270 472
249 }
250 478 my $gaps;
251 478 ▶ if ( $calls ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($calls) 204 274 478
252 18 $gaps = [ map { +{ call => $_, tool => $calls->[$_]{tool}, gap => $calls->[$_]{sim_gap} } }
253 204 grep { defined $calls->[$_]{sim_gap} } 0 .. $#$calls ];
254 }
255 return {
256 4302 ( map { $_ => $r->{$_} } qw( repetition seed status score error rules diff forbidden_calls injection_held ) ),
257 finish_reason => $finish,
258 duration_ms => $duration,
259 turns => $turns,
260 tokens => \%tokens,
261 calls => $calls,
262 sim_gaps => $gaps,
263 478 transcript => scalar $self->_transcript( $r->{transcript}, $where ),
264 };
265 }
266  
267 478 ▶sub _transcript {
Subroutine _transcript: called CC=8 SCAR=20.9
268 478 my ( $self, $messages, $where ) = @_;
269 478 ▶ return unless $self->with_transcript && defined $messages;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->with_transcript and defined $messages 469 9 478
Condition100%3/3
$self->with_transcript and defined $messages
!ll&&!rl&&r
46189
MC/DC100%2/2
$self->with_transcript and defined $messages
$self->with_transcript defined $messages
Truth table100%3/3
A and B
A= $self->with_transcriptB= defined $messages
ABresult
0X0
100
111
270 9 ▶ croak __PACKAGE__.' '.$where.'.transcript must be an array' unless ref $messages eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $messages eq "ARRAY" 0 9 9
271 9 my @out;
272 9 for my $m ( @$messages ) {
273 14 ▶ if ( ref $m eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $m eq "HASH") 14 0 14
274 14 ▶ next if defined $m->{role} && $m->{role} eq 'system';
Branch: 1 branch
BranchTrueFalseTotal
if defined $m->{"role"} and $m->{"role"} eq "system" 2 12 14
Condition100%3/3
defined $m->{"role"} and $m->{"role"} eq "system"
!ll&&!rl&&r
1112
MC/DC100%2/2
defined $m->{"role"} and $m->{"role"} eq "system"
defined $m->{"role"} $m->{"role"} eq "system"
Truth table100%3/3
A and B
A= defined $m->{"role"}B= $m->{"role"} eq "system"
ABresult
0X0
100
111
275 12 my %copy = %$m;
276 12 delete $copy{untrusted};
277 12 push @out, \%copy;
278 12 next;
279 }
280 0 push @out, $m;
281 }
282 9 return \@out;
283 }
284  
285 128 ▶sub finish {
Subroutine finish: called CC=2 SCAR=6.9
Pod documented
286 128 my ( $self, $at ) = @_;
287 128 ▶ $self->_set_finished_at( defined $at ? $at : $self->now );
Branch: 1 branch
BranchTrueFalseTotal
defined $at ? : 78 50 128
288 128 return $self;
289 }
290  
291  
292 1 ▶sub image_entry {
Subroutine image_entry: called CC=5 SCAR=19.4
Pod documented
293 1 my ( $self, $name, $bytes ) = @_;
294 1 ▶ croak __PACKAGE__.'->image_entry needs a name and the image bytes' unless defined $name && defined $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and defined $bytes 0 1 1
Condition33%1/3
defined $name and defined $bytes
!ll&&!rl&&r
001
MC/DC0%0/2
defined $name and defined $bytes
defined $name defined $bytes
Truth table33%1/3
A and B
A= defined $nameB= defined $bytes
ABresult
0X0
100
111
295 1 ▶ croak __PACKAGE__.'->image_entry wants bytes, got characters' if utf8::is_utf8($bytes) && $bytes =~ /[^\x00-\xff]/;
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($bytes) and $bytes =~ /[^\x00-\xff]/ 0 1 1
Condition33%1/3
utf8::is_utf8($bytes) and $bytes =~ /[^\x00-\xff]/
!ll&&!rl&&r
100
MC/DC0%0/2
utf8::is_utf8($bytes) and $bytes =~ /[^\x00-\xff]/
utf8::is_utf8($bytes) $bytes =~ /[^\x00-\xff]/
Truth table33%1/3
A and B
A= utf8::is_utf8($bytes)B= $bytes =~ /[^\x00-\xff]/
ABresult
0X0
100
111
296 1 return { image => ''.$name, sha256 => sha256_hex($bytes), bytes => length $bytes };
297 }
298  
299  
300 #### Writing and reading
301  
302 52 ▶sub as_data {
Subroutine as_data: called CC=1 SCAR=0.0
Pod documented
303 52 my ( $self ) = @_;
304 return {
305 52 holmgang_report => $self->format_version,
306 generator => $self->_shape( 'generator', $self->generator, 'generator', 0 ),
307 started_at => $self->_shape( 'time', $self->started_at, 'started_at', 0 ),
308 finished_at => $self->_shape( 'time', $self->finished_at, 'finished_at', 0 ),
309 runs => $self->runs,
310 };
311 }
312  
313  
314 222 ▶sub _json {
Subroutine _json: called CC=1 SCAR=0.0
315 222 return JSON::MaybeXS->new( utf8 => 1, canonical => 1, pretty => 1, convert_blessed => 1 );
316 }
317  
318 52 ▶sub to_json { my ( $self ) = @_; return $self->_json->encode( $self->as_data ) }
Subroutine to_json: called CC=1 SCAR=0.0
Pod documented
319  
320  
321 23 ▶sub write {
Subroutine write: called CC=2 SCAR=7.0
Pod documented
322 23 my ( $self, $file ) = @_;
323 23 ▶ croak __PACKAGE__.'->write needs a file' unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 23 23
324 23 path($file)->spew_raw( $self->to_json );
325 22 return $self;
326 }
327  
328  
329 58 ▶sub from_json {
Subroutine from_json: called CC=9 SCAR=22.2
Pod documented
330 58 my ( $class, $bytes, %arg ) = @_;
331 58 ▶ my $from = defined $arg{source} ? $arg{source} : 'report';
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{'source'} ? : 48 10 58
332 58 my $data = eval { $class->_json->decode($bytes) };
333 58 ▶ croak __PACKAGE__.' '.$from.' is not JSON: '.( $@ =~ s/\s+\z//r ) unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 2 56 58
334 56 ▶ croak __PACKAGE__.' '.$from.' is not a Holmgang report' unless ref $data eq 'HASH' && exists $data->{holmgang_report};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" and exists $data->{"holmgang_report"} 3 53 56
Condition66%2/3
ref $data eq "HASH" and exists $data->{"holmgang_report"}
!ll&&!rl&&r
0353
MC/DC50%1/2
ref $data eq "HASH" and exists $data->{"holmgang_report"}
ref $data eq "HASH" exists $data->{"holmgang_report"}
Truth table66%2/3
A and B
A= ref $data eq "HASH"B= exists $data->{"holmgang_report"}
ABresult
0X0
100
111
335 53 my $v = $data->{holmgang_report};
336 53 ▶ croak __PACKAGE__.' '.$from.': holmgang_report must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and not ref $v and $v =~ /\A[1-9][0-9]*\z/ 1 52 53
Condition50%3/6
defined $v and not ref $v and $v =~ /\A[1-9][0-9]*\z/
!ll&&!rl&&r
0152
defined $v and not ref $v
!ll&&!rl&&r
0053
MC/DC33%1/3
defined $v and not ref $v and $v =~ /\A[1-9][0-9]*\z/
defined $v not ref $v $v =~ /\A[1-9][0-9]*\z/
Truth table50%2/4
A and not(B) and C
A= defined $vB= not ref $vC= $v =~ /\A[1-9][0-9]*\z/
ABCresult
0XX0
10X0
1100
1111
337 unless defined $v && !ref $v && $v =~ /\A[1-9][0-9]*\z/;
338 52 ▶ croak __PACKAGE__.' '.$from.': unknown report version '.$v.' (this reader knows up to '.$class->format_version.')'
Branch: 1 branch
BranchTrueFalseTotal
if $v > $class->format_version 1 51 52
339 if $v > $class->format_version;
340 51 my $doc = $class->_shape( 'report', $data, $from, 1 );
341 return $class->new(
342 generator => $doc->{generator},
343 started_at => $doc->{started_at},
344 finished_at => $doc->{finished_at},
345 runs => $doc->{runs},
346 45 );
347 }
348  
349  
350 43 ▶sub read {
Subroutine read: called CC=2 SCAR=7.1
Pod documented
351 43 my ( $class, $file ) = @_;
352 43 ▶ croak __PACKAGE__.'->read needs a file' unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 43 43
353 43 return $class->from_json( path($file)->slurp_raw, source => ''.$file );
354 }
355  
356  
357 #### Merging
358  
359 112 ▶sub merge {
Subroutine merge: called CC=17 SCAR=28.3
Pod documented
360 112 my ( $class, @reports ) = @_;
361 112 ▶ croak __PACKAGE__.'->merge needs at least one report' unless @reports;
Branch: 1 branch
BranchTrueFalseTotal
unless @reports 0 112 112
362 112 my ( %run, @order );
363 112 my $json = $class->_json;
364 112 for my $rep ( @reports ) {
365 127 for my $run ( @{ $rep->runs } ) {
366 160 my $key = $json->encode( { map { $_ => $run->{$_} } qw( target variant suite ) } );
367 160 ▶ unless ( $run{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($run{$key}) 149 11 160
368 149 push @order, $key;
369 149 $run{$key} = { %$run, cases => [] , _case => {} };
370 }
371 160 my $m = $run{$key};
372 croak __PACKAGE__.'->merge: run of suite '.$run->{suite}{id}.' has repeat '.$m->{repeat}.' and '.$run->{repeat}
373 160 ▶ unless $m->{repeat} == $run->{repeat};
Branch: 1 branch
BranchTrueFalseTotal
unless $m->{"repeat"} == $run->{"repeat"} 1 159 160
374 159 $m->{status} = $class->_worse_status( $m->{status}, $run->{status} );
375 159 ▶ $m->{error} = $run->{error} unless defined $m->{error};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m->{"error"} 151 8 159
376 159 for my $c ( @{ $run->{cases} } ) {
377 258 my $mc = $m->{_case}{ $c->{case_id} };
378 258 ▶ unless ( $mc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mc) 249 9 258
379 249 $mc = $m->{_case}{ $c->{case_id} } = { %$c, repetitions => [] };
380 249 push @{ $m->{cases} }, $mc;
381 }
382 # a field added after version 1 is null in an older report: the other's value holds
383 258 for my $f ( $class->_optional_case_fields ) {
384 258 ▶ $mc->{$f} = $c->{$f} unless defined $mc->{$f};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mc->{$f} 224 34 258
385 }
386 258 my %meta_a = %$mc; delete $meta_a{repetitions};
387 258 my %meta_b = %$c; delete $meta_b{repetitions};
388 258 ▶ defined $meta_b{$_} or $meta_b{$_} = $meta_a{$_} for $class->_optional_case_fields;
Branch: 1 branch
BranchTrueFalseTotal
defined $meta_b{$_} or $meta_b{$_} = $meta_a{$_} 34 224 258
389 258 ▶ croak __PACKAGE__.'->merge: case '.$c->{case_id}.' of suite '.$run->{suite}{id}.' differs between reports'
Branch: 1 branch
BranchTrueFalseTotal
unless $json->encode(\%meta_a) eq $json->encode(\%meta_b) 2 256 258
390 unless $json->encode( \%meta_a ) eq $json->encode( \%meta_b );
391 256 for my $r ( @{ $c->{repetitions} } ) {
392 382 my ($have) = grep { $_->{repetition} == $r->{repetition} } @{ $mc->{repetitions} };
393 382 ▶ unless ( $have ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($have) 376 6 382
394 376 push @{ $mc->{repetitions} }, $r;
395 376 next;
396 }
397 croak __PACKAGE__.'->merge: case '.$c->{case_id}.' repetition '.$r->{repetition}.' of suite '
398 6 ▶ .$run->{suite}{id}.' is in two reports with different results'
Branch: 1 branch
BranchTrueFalseTotal
unless $json->encode($class->_stable($have)) eq $json->encode($class->_stable($r)) 1 5 6
399 unless $json->encode( $class->_stable($have) ) eq $json->encode( $class->_stable($r) );
400 }
401 255 @{ $mc->{repetitions} } = sort { $a->{repetition} <=> $b->{repetition} } @{ $mc->{repetitions} };
402 }
403 }
404 }
405 108 my @runs = map { my $r = $run{$_}; delete $r->{_case}; $r } @order;
406 108 my @start = sort grep { defined } map { $_->started_at } @reports;
407 108 my @finish = sort grep { defined } map { $_->finished_at } @reports;
408 108 return $class->new(
409 generator => $reports[0]->generator,
410 started_at => $start[0],
411 finished_at => $finish[-1],
412 runs => \@runs,
413 );
414 }
415  
416  
417 516 ▶sub _optional_case_fields {
Subroutine _optional_case_fields: called CC=2 SCAR=6.9
418 516 my $f = $SPEC{case}{fields};
419 516 ▶ return grep { ref $f->{$_} && $f->{$_}{optional} } sort keys %$f;
Condition100%3/3
ref $f->{$_} && $f->{$_}{'optional'}
!ll&&!rl&&r
20642064516
MC/DC100%2/2
ref $f->{$_} && $f->{$_}{'optional'}
ref $f->{$_} $f->{$_}{'optional'}
Truth table100%3/3
A && B
A= ref $f->{$_}B= $f->{$_}{'optional'}
ABresult
0X0
100
111
420 }
421  
422 163 ▶sub _worse_status {
Subroutine _worse_status: called CC=2 SCAR=6.9
423 163 my ( $self, $x, $y ) = @_;
424 163 my %rank = ( complete => 0, cancelled => 1, aborted => 2 );
425 163 ▶ return $rank{$y} > $rank{$x} ? $y : $x;
Branch: 1 branch
BranchTrueFalseTotal
$rank{$y} > $rank{$x} ? : 1 162 163
426 }
427  
428 # A repetition without its volatile fields, for comparison.
429 14 ▶sub _stable {
Subroutine _stable: called CC=2 SCAR=6.9
430 14 my ( $self, $r ) = @_;
431 14 my %copy = %$r;
432 14 delete $copy{duration_ms};
433 14 ▶ $copy{turns} = [ map { my %t = %$_; delete $t{duration_ms}; \%t } @{ $r->{turns} } ] if $r->{turns};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"turns"} 14 0 14
434 14 return \%copy;
435 }
436  
437 #### Shape
438  
439 56962 ▶sub _shape {
Subroutine _shape: called CC=41 SCAR=37.6
440 56962 my ( $self, $spec, $value, $where, $strict ) = @_;
441 56962 ▶ $spec = $SPEC{$spec} || { type => $spec } unless ref $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec 24414 32548 56962
Condition100%2/2
$SPEC{$spec} || {'type', $spec}
l!l
286421550
MC/DC100%1/1
$SPEC{$spec} || {'type', $spec}
$SPEC{$spec}
Truth table100%2/2
A
A= $SPEC{$spec}
Aresult
11
00
442 56962 my $type = $spec->{type};
443 56962 ▶ unless ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 19639 37323 56962
444 19639 ▶ croak __PACKAGE__.' '.$where.' must not be null' if defined $spec->{null} && !$spec->{null};
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec->{"null"} and not $spec->{"null"} 1 19638 19639
Condition66%2/3
defined $spec->{"null"} and not $spec->{"null"}
!ll&&!rl&&r
1963801
MC/DC50%1/2
defined $spec->{"null"} and not $spec->{"null"}
defined $spec->{"null"} not $spec->{"null"}
Truth table66%2/3
A and not(B)
A= defined $spec->{"null"}B= not $spec->{"null"}
ABresult
0X0
100
111
445 19638 return undef;
446 }
447 37323 ▶ if ( $type eq 'object' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "object") 7653 29670 37323
448 7653 ▶ croak __PACKAGE__.' '.$where.' must be an object' unless ref $value eq 'HASH' && !blessed $value;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" and not builtin::blessed($value) 0 7653 7653
Condition33%1/3
ref $value eq "HASH" and not builtin::blessed($value)
!ll&&!rl&&r
007653
MC/DC0%0/2
ref $value eq "HASH" and not builtin::blessed($value)
ref $value eq "HASH" not builtin::blessed($value)
Truth table33%1/3
A and not(B)
A= ref $value eq "HASH"B= not builtin::blessed($value)
ABresult
0X0
100
111
449 7653 my %out;
450 7653 for my $f ( sort keys %{ $spec->{fields} } ) {
451 50510 my $fs = $spec->{fields}{$f};
452 croak __PACKAGE__.' '.$where.'.'.$f.' is missing'
453 50510 ▶ if $strict && !exists $value->{$f} && !( ref $fs && $fs->{optional} );
Branch: 1 branch
BranchTrueFalseTotal
if $strict and not exists $value->{$f} and not ref $fs && $fs->{"optional"} 3 50507 50510
Condition100%9/9
$strict and not exists $value->{$f} and not ref $fs && $fs->{"optional"}
!ll&&!rl&&r
5050343
$strict and not exists $value->{$f}
!ll&&!rl&&r
4466658377
ref $fs && $fs->{'optional'}
!ll&&!rl&&r
214
MC/DC100%4/4
$strict and not exists $value->{$f} and not ref $fs && $fs->{"optional"}
$strict not exists $value->{$f} ref $fs $fs->{'optional'}
Truth table100%5/5
A and not(B) and not(C && D)
A= $strictB= not exists $value->{$f}C= ref $fsD= $fs->{'optional'}
ABCDresult
0XXX0
10XX0
11110
110X1
11101
454 50507 $out{$f} = $self->_shape( $fs, $value->{$f}, $where.'.'.$f, $strict );
455 }
456 7601 return \%out;
457 }
458 29670 ▶ if ( $type eq 'array' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "array") 5186 24484 29670
459 5186 ▶ croak __PACKAGE__.' '.$where.' must be an array' unless ref $value eq 'ARRAY' && !blessed $value;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" and not builtin::blessed($value) 0 5186 5186
Condition33%1/3
ref $value eq "ARRAY" and not builtin::blessed($value)
!ll&&!rl&&r
005186
MC/DC0%0/2
ref $value eq "ARRAY" and not builtin::blessed($value)
ref $value eq "ARRAY" not builtin::blessed($value)
Truth table33%1/3
A and not(B)
A= ref $value eq "ARRAY"B= not builtin::blessed($value)
ABresult
0X0
100
111
460 5186 my $of = $spec->{of};
461 5186 ▶ my $el = ref $of ? { %$of, null => 0 } : $SPEC{$of} ? { %{ $SPEC{$of} }, null => 0 } : { type => $of, null => 0 };
Branch: 2 branches
BranchTrueFalseTotal
ref $of ? : 0 5186 5186
$SPEC{$of} ? : 4781 405 5186
462 5186 return [ map { $self->_shape( $el, $value->[$_], $where.'['.$_.']', $strict ) } 0 .. $#$value ];
463 }
464 24484 ▶ return $self->_any( $value, $where, $strict ) if $type eq 'any';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "any" 1550 22934 24484
465 22934 ▶ if ( $type eq 'bool' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "bool") 3465 19469 22934
466 3465 ▶ if ( JSON::MaybeXS::is_bool($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (JSON::MaybeXS::is_bool($value)) 2033 1432 3465
467 2033 ▶ return $value ? JSON::MaybeXS::true() : JSON::MaybeXS::false();
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1316 717 2033
468 }
469 1432 ▶ croak __PACKAGE__.' '.$where.' must be a JSON boolean' if $strict || ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if $strict or ref $value 1 1431 1432
Condition66%2/3
$strict or ref $value
l!l&&r!l&&!r
101431
MC/DC50%1/2
$strict or ref $value
$strict ref $value
Truth table66%2/3
A or B
A= $strictB= ref $value
ABresult
1X1
011
000
470 1431 ▶ return $value ? JSON::MaybeXS::true() : JSON::MaybeXS::false();
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 878 553 1431
471 }
472 19469 ▶ croak __PACKAGE__.' '.$where.' must be a scalar' if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 19469 19469
473 19469 ▶ if ( $type eq 'int' || $type eq 'num' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "int" or $type eq "num") 7462 12007 19469
Condition100%3/3
$type eq "int" or $type eq "num"
l!l&&r!l&&!r
6271119112007
MC/DC100%2/2
$type eq "int" or $type eq "num"
$type eq "int" $type eq "num"
Truth table100%3/3
A or B
A= $type eq "int"B= $type eq "num"
ABresult
1X1
011
000
474 7462 ▶ my $re = $type eq 'int' ? qr/\A-?[0-9]+\z/ : qr/\A-?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][-+]?[0-9]+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'int' ? : 6271 1191 7462
475 7462 ▶ croak __PACKAGE__.' '.$where.' must be '.( $type eq 'int' ? 'an integer' : 'a number' ).", got '".$value."'"
Branch: 2 branches
BranchTrueFalseTotal
unless $value =~ /$re/ 1 7461 7462
$type eq 'int' ? : 1 0 1
476 unless $value =~ $re;
477 7461 my $n = 0 + $value;
478 7461 ▶ croak __PACKAGE__.' '.$where.' must be at least '.$spec->{min} if defined $spec->{min} && $n < $spec->{min};
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec->{"min"} and $n < $spec->{"min"} 0 7461 7461
Condition66%2/3
defined $spec->{"min"} and $n < $spec->{"min"}
!ll&&!rl&&r
6273990
MC/DC0%0/2
defined $spec->{"min"} and $n < $spec->{"min"}
defined $spec->{"min"} $n < $spec->{"min"}
Truth table66%2/3
A and B
A= defined $spec->{"min"}B= $n < $spec->{"min"}
ABresult
0X0
100
111
479 7461 ▶ croak __PACKAGE__.' '.$where.' must be at most '.$spec->{max} if defined $spec->{max} && $n > $spec->{max};
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec->{"max"} and $n > $spec->{"max"} 1 7460 7461
Condition100%3/3
defined $spec->{"max"} and $n > $spec->{"max"}
!ll&&!rl&&r
69984621
MC/DC100%2/2
defined $spec->{"max"} and $n > $spec->{"max"}
defined $spec->{"max"} $n > $spec->{"max"}
Truth table100%3/3
A and B
A= defined $spec->{"max"}B= $n > $spec->{"max"}
ABresult
0X0
100
111
480 7460 return $n;
481 }
482 12007 my $text = ''.$value;
483 12007 $self->_check_text( $text, $where );
484 12006 ▶ if ( $type eq 'enum' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'enum') { } 1457 10549 12006
elsif ($type eq 'time') { } 179 10370 10549
elsif ($type eq 'url') { } 103 10267 10370
485 1457 ▶ croak __PACKAGE__.' '.$where.": unknown value '".$text."'" unless grep { $_ eq $text } @{ $spec->{values} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $text;} @{$$spec{"values"};} 3 1454 1457
486 }
487 elsif ( $type eq 'time' ) {
488 179 ▶ croak __PACKAGE__.' '.$where.": not an ISO-8601 time '".$text."'"
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\A[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}(?::[0-9]{2}(?:\.[0-9]+)?)?(?:Z|[-+][0-9]{2}:?[0-9]{2})\z/ 0 179 179
489 unless $text =~ /\A[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}(?::[0-9]{2}(?:\.[0-9]+)?)?(?:Z|[-+][0-9]{2}:?[0-9]{2})\z/;
490 }
491 elsif ( $type eq 'url' ) {
492 103 return $self->_clean_url($text);
493 }
494 11900 return $text;
495 }
496  
497 # Deep copy of free data (arguments, diff values, settings, transcript):
498 # booleans normalised, objects and image content refused.
499 2356 ▶sub _any {
Subroutine _any: called CC=12 SCAR=24.9
500 2356 my ( $self, $value, $where, $strict ) = @_;
501 2356 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 2355 2356
502 2355 ▶ return $value ? JSON::MaybeXS::true() : JSON::MaybeXS::false() if JSON::MaybeXS::is_bool($value);
Branch: 2 branches
BranchTrueFalseTotal
if JSON::MaybeXS::is_bool($value) 22 2333 2355
$value ? : 15 7 22
503 2333 ▶ croak __PACKAGE__.' '.$where.' holds an object ('.ref($value).'); only plain data goes into a report'
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) 1 2332 2333
504 if blessed $value;
505 2332 ▶ if ( ref $value eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "HASH") 979 1353 2332
506 croak __PACKAGE__.' '.$where.' holds base64 image content'
507 if ( ref $value->{source} eq 'HASH' && ( $value->{source}{type} // '' ) eq 'base64' )
508 979 ▶ || grep { exists $value->{$_} } qw( inline_data inlineData b64_json );
Branch: 1 branch
BranchTrueFalseTotal
if ref $value->{"source"} eq "HASH" and ($value->{"source"}{"type"} // "") eq "base64" or grep {exists $value->{$_};} "inline_data", "inlineData", "b64_json" 2 977 979
Condition75%6/8
ref $value->{"source"} eq "HASH" and ($value->{"source"}{"type"} // "") eq "base64" or grep {exists $value->{$_};} "inline_data", "inlineData", "b64_json"
l!l&&r!l&&!r
11977
ref $value->{"source"} eq "HASH" and ($value->{"source"}{"type"} // "") eq "base64"
!ll&&!rl&&r
97801
$value->{"source"}{"type"} // ""
l!l
10
MC/DC66%2/3
ref $value->{"source"} eq "HASH" and ($value->{"source"}{"type"} // "") eq "base64" or grep {exists $value->{$_};} "inline_data", "inlineData", "b64_json"
ref $value->{"source"} eq "HASH" $value->{"source"}{"type"} grep {exists $value->{$_};} "inline_data", "inlineData", "b64_json"
Truth table60%3/5
A and B or C
A= ref $value->{"source"} eq "HASH"B= $value->{"source"}{"type"}C= grep {exists $value->{$_};} "inline_data", "inlineData", "b64_json"
ABCresult
11X1
0X11
1011
0X00
1000
509 977 return { map { $_ => $self->_any( $value->{$_}, $where.'.'.$_, $strict ) } keys %$value };
510 }
511 1353 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 38 1315 1353
512 38 return [ map { $self->_any( $value->[$_], $where.'['.$_.']', $strict ) } 0 .. $#$value ];
513 }
514 1315 ▶ croak __PACKAGE__.' '.$where.' holds a '.ref($value).' reference' if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 1315 1315
515 1315 $self->_check_text( $value, $where );
516 1311 return $value;
517 }
518  
519 13322 ▶sub _check_text {
Subroutine _check_text: called CC=4 SCAR=13.9
520 13322 my ( $self, $text, $where ) = @_;
521 13322 ▶ croak __PACKAGE__.' '.$where.' holds a data: URL; images go into a report only as { image, sha256, bytes }'
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /$DATA_URL/ 4 13318 13322
522 if $text =~ $DATA_URL;
523 13318 ▶ croak __PACKAGE__.' '.$where.' holds base64 content; images go into a report only as { image, sha256, bytes }'
Branch: 1 branch
BranchTrueFalseTotal
if length $text >= 1024 and $text =~ /$BASE64_RUN/ 1 13317 13318
Condition100%3/3
length $text >= 1024 and $text =~ /$BASE64_RUN/
!ll&&!rl&&r
1331521
MC/DC100%2/2
length $text >= 1024 and $text =~ /$BASE64_RUN/
length $text >= 1024 $text =~ /$BASE64_RUN/
Truth table100%3/3
A and B
A= length $text >= 1024B= $text =~ /$BASE64_RUN/
ABresult
0X0
100
111
524 if length $text >= 1024 && $text =~ $BASE64_RUN;
525 13317 return;
526 }
527  
528 103 ▶sub _clean_url {
Subroutine _clean_url: called CC=8 SCAR=20.9
529 103 my ( $self, $text ) = @_;
530 103 my $uri = URI->new($text);
531 103 ▶ return $text unless $uri->scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri->scheme 0 103 103
532 103 $uri->fragment(undef);
533 103 ▶ $uri->userinfo(undef) if $uri->can('userinfo');
Branch: 1 branch
BranchTrueFalseTotal
if $uri->can("userinfo") 103 0 103
534 103 ▶ if ( $uri->can('query_form') && defined $uri->query ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri->can("query_form") and defined $uri->query) 24 79 103
Condition66%2/3
$uri->can("query_form") and defined $uri->query
!ll&&!rl&&r
07924
MC/DC50%1/2
$uri->can("query_form") and defined $uri->query
$uri->can("query_form") defined $uri->query
Truth table66%2/3
A and B
A= $uri->can("query_form")B= defined $uri->query
ABresult
0X0
100
111
535 24 my @q = $uri->query_form;
536 24 my @keep;
537 24 ▶ while ( my ( $k, $v ) = splice @q, 0, 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@q, 0, 2)) 37 24 61
538 37 ▶ push @keep, $k, $v unless $k =~ $SECRET_PARAM;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /$SECRET_PARAM/ 22 15 37
539 }
540 24 $uri->query_form( \@keep );
541 24 ▶ $uri->query(undef) unless @keep;
Branch: 1 branch
BranchTrueFalseTotal
unless @keep 2 22 24
542 }
543 103 return $uri->as_string;
544 }
545  
546 #### cai-platform
547  
548 5 ▶sub from_cai_platform {
Subroutine from_cai_platform: called CC=29 SCAR=34.2
Pod documented
549 5 my ( $class, $data, %arg ) = @_;
550 croak __PACKAGE__.'->from_cai_platform needs the decoded --report hash'
551 5 ▶ unless ref $data eq 'HASH' && ref $data->{runs} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" and ref $data->{"runs"} eq "ARRAY" 1 4 5
Condition66%2/3
ref $data eq "HASH" and ref $data->{"runs"} eq "ARRAY"
!ll&&!rl&&r
014
MC/DC50%1/2
ref $data eq "HASH" and ref $data->{"runs"} eq "ARRAY"
ref $data eq "HASH" ref $data->{"runs"} eq "ARRAY"
Truth table66%2/3
A and B
A= ref $data eq "HASH"B= ref $data->{"runs"} eq "ARRAY"
ABresult
0X0
100
111
552 4 ▶ my $grading = $arg{grading} || {};
Condition100%2/2
$arg{'grading'} || {}
l!l
13
MC/DC100%1/1
$arg{'grading'} || {}
$arg{'grading'}
Truth table100%2/2
A
A= $arg{'grading'}
Aresult
11
00
553 4 ▶ my $suites = $arg{suites} || {};
Condition100%2/2
$arg{'suites'} || {}
l!l
13
MC/DC100%1/1
$arg{'suites'} || {}
$arg{'suites'}
Truth table100%2/2
A
A= $arg{'suites'}
Aresult
11
00
554 4 ▶ my %model = map { $_ => 1 } @{ $data->{models} || [] };
Condition50%1/2
$data->{'models'} || []
l!l
40
MC/DC0%0/1
$data->{'models'} || []
$data->{'models'}
Truth table50%1/2
A
A= $data->{'models'}
Aresult
11
00
555 4 my ( %group, @order );
556 4 for my $row ( @{ $data->{runs} } ) {
557 8 ▶ my $key = join "\0", map { defined $_ ? $_ : '' } $row->{target}, $row->{suite_id};
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 16 0 16
558 8 ▶ push @order, $key unless $group{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $group{$key} 4 4 8
559 8 push @{ $group{$key} }, $row;
560 }
561 4 my %run_status = ( done => 'complete', cancelled => 'cancelled', failed => 'aborted' );
562 4 my @runs;
563 4 for my $key ( @order ) {
564 4 my @rows = @{ $group{$key} };
565 4 my $first = $rows[0];
566 4 my $sid = $first->{suite_id};
567 4 ▶ my $meta = $suites->{$sid} || {};
Condition100%2/2
$suites->{$sid} || {}
l!l
13
MC/DC100%1/1
$suites->{$sid} || {}
$suites->{$sid}
Truth table100%2/2
A
A= $suites->{$sid}
Aresult
11
00
568 4 ▶ my $repeat = ( $data->{repeat_by_suite} || {} )->{$sid};
Condition50%1/2
$data->{'repeat_by_suite'} || {}
l!l
40
MC/DC0%0/1
$data->{'repeat_by_suite'} || {}
$data->{'repeat_by_suite'}
Truth table50%1/2
A
A= $data->{'repeat_by_suite'}
Aresult
11
00
569 4 ▶ $repeat = @rows unless defined $repeat;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repeat 0 4 4
570 4 ▶ croak __PACKAGE__.'->from_cai_platform: '.scalar(@rows).' runs of '.$first->{target}.'/'.$sid.' for repeat '.$repeat
Branch: 1 branch
BranchTrueFalseTotal
if @rows > $repeat 1 3 4
571 if @rows > $repeat;
572 3 my $status = 'complete';
573 3 my $error;
574 3 my ( %case, @case_order );
575 3 for my $i ( 0 .. $#rows ) {
576 5 my $row = $rows[$i];
577 my $s = $run_status{ $row->{status} // '' }
578 5 ▶ or croak __PACKAGE__.'->from_cai_platform: unknown run status '.( $row->{status} // '(none)' );
Branch: 1 branch
BranchTrueFalseTotal
my $s = $run_status{$row->{"status"} // ""} or croak('Langertha::Holmgang::Report->from_cai_platform: unknown run status ' . ($row->{"status"} // "(none)")) 4 1 5
Condition50%2/4
$row->{"status"} // ""
l!l
50
$row->{"status"} // "(none)"
l!l
10
MC/DC0%0/1
$row->{"status"} // ""
$row->{"status"}
MC/DC0%0/1
$row->{"status"} // "(none)"
$row->{"status"}
Truth table50%1/2
A
A= $row->{"status"}
Aresult
11
00
Truth table50%1/2
A
A= $row->{"status"}
Aresult
11
00
579 4 $status = $class->_worse_status( $status, $s );
580 4 ▶ $error = $row->{error} unless defined $error;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error 4 0 4
581 4 ▶ for my $c ( @{ $row->{cases} || [] } ) {
Condition50%1/2
$row->{'cases'} || []
l!l
40
MC/DC0%0/1
$row->{'cases'} || []
$row->{'cases'}
Truth table50%1/2
A
A= $row->{'cases'}
Aresult
11
00
582 7 my $id = $c->{case_id};
583 7 ▶ unless ( $case{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($case{$id}) 5 2 7
584 5 ▶ my $cm = ( $meta->{cases} || {} )->{$id} || {};
Condition100%4/4
+($meta->{'cases'} || {})->{$id} || {}
l!l
23
$meta->{'cases'} || {}
l!l
23
MC/DC100%1/1
+($meta->{'cases'} || {})->{$id} || {}
$meta->{'cases'}
Truth table100%2/2
A
A= $meta->{'cases'}
Aresult
11
00
585 $case{$id} = {
586 case_id => $id,
587 title => $c->{title},
588 difficulty => defined $c->{difficulty} ? $c->{difficulty} : $cm->{difficulty},
589 5 ▶ ( map { $_ => $cm->{$_} } qw( tags tier weight hard untrusted ) ),
Branch: 1 branch
BranchTrueFalseTotal
defined $c->{'difficulty'} ? : 3 2 5
590 repetitions => [],
591 };
592 5 push @case_order, $id;
593 }
594 7 ▶ my $g = defined $row->{id} ? ( $grading->{ $row->{id} } || {} )->{$id} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $row->{'id'} ? : 7 0 7
Condition100%2/2
$$grading{$row->{'id'}} || {}
l!l
25
MC/DC100%1/1
$$grading{$row->{'id'}} || {}
$$grading{$row->{'id'}}
Truth table100%2/2
A
A= $$grading{$row->{'id'}}
Aresult
11
00
595 7 push @{ $case{$id}{repetitions} }, $class->_cai_repetition( $c, $g, $i + 1, $repeat );
596 }
597 }
598 push @runs, {
599 target => {
600 label => $first->{target},
601 engine => undef,
602 model => $model{ $first->{target} // '' } ? $first->{target} : undef,
603 url => $data->{base_url},
604 },
605 variant => { name => undef, settings => undef },
606 suite => { id => $sid, version => $meta->{version}, topic => $first->{topic}, digest => $meta->{digest} },
607 repeat => $repeat,
608 status => $status,
609 error => $error,
610 1 ▶ cases => [ map { $case{$_} } @case_order ],
Branch: 1 branch
BranchTrueFalseTotal
$model{$first->{'target'} // ''} ? : 1 0 1
Condition50%1/2
$first->{"target"} // ""
l!l
10
MC/DC0%0/1
$first->{"target"} // ""
$first->{"target"}
Truth table50%1/2
A
A= $first->{"target"}
Aresult
11
00
611 };
612 }
613 1 return $class->new( started_at => undef, runs => \@runs );
614 }
615  
616  
617 7 ▶sub _cai_repetition {
Subroutine _cai_repetition: called CC=25 SCAR=33.6
618 7 my ( $self, $c, $g, $n, $repeat ) = @_;
619 7 ▶ my $exceeded = $c->{exceeded} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$c->{'exceeded'} ? : 3 4 7
620 7 ▶ my $st = $c->{status} // '';
Condition50%1/2
$c->{"status"} // ""
l!l
70
MC/DC0%0/1
$c->{"status"} // ""
$c->{"status"}
Truth table50%1/2
A
A= $c->{"status"}
Aresult
11
00
621 my $status = ( $exceeded && ( $st eq 'failed' || $st eq 'ungraded' ) ) ? 'turn_limit'
622 : $st eq 'ungraded' ? 'uncertain'
623 12 ▶ : ( grep { $_ eq $st } qw( passed failed error context_exceeded ) ) ? $st
Branch: 1 branch
BranchTrueFalseTotal
length $st ? : 1 0 1
624 7 ▶ : croak __PACKAGE__.'->from_cai_platform: unknown case status '.( length $st ? $st : '(none)' ).' for '.$c->{case_id};
Branch: 3 branches
BranchTrueFalseTotal
$exceeded && ($st eq 'failed' || $st eq 'ungraded') ? : 3 4 7
$st eq 'ungraded' ? : 1 3 4
grep({$_ eq $st;} 'passed', 'failed', 'error', 'context_exceeded') ? : 2 1 3
Condition66%4/6
$exceeded and $st eq "failed" || $st eq "ungraded"
!ll&&!rl&&r
403
$st eq "failed" or $st eq "ungraded"
l!l&&r!l&&!r
120
MC/DC33%1/3
$exceeded and $st eq "failed" || $st eq "ungraded"
$exceeded $st eq "failed" $st eq "ungraded"
Truth table75%3/4
A and B or C
A= $exceededB= $st eq "failed"C= $st eq "ungraded"
ABCresult
0XX0
1000
11X1
1011
625 6 my ( $rules, $diff, $score );
626 6 ▶ my @calls = map { +{ tool => undef, args => undef, succeeded => undef, sim_gap => undef } } 1 .. ( $c->{tool_calls} || 0 );
Condition50%1/2
$c->{'tool_calls'} || 0
l!l
60
MC/DC0%0/1
$c->{'tool_calls'} || 0
$c->{'tool_calls'}
Truth table50%1/2
A
A= $c->{'tool_calls'}
Aresult
11
00
627 6 my $gaps;
628 6 ▶ if ( ref $g eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $g eq 'HASH') { } 1 5 6
629 $rules = [ map { +{
630 title => $_->{title},
631 kind => $_->{kind},
632 required => $_->{required} ? 1 : 0,
633 passed => $_->{passed} ? 1 : 0,
634 reason => $_->{detail},
635 sim_gap => $_->{sim_gap},
636 1 ▶ } } grep { ( $_->{kind} // '' ) ne 'turns' } @{ $g->{rules} || [] } ];
Branch: 2 branches
BranchTrueFalseTotal
$_->{'required'} ? : 2 0 2
$_->{'passed'} ? : 1 1 2
Condition50%2/4
$_->{"kind"} // ""
l!l
30
$g->{'rules'} || []
l!l
10
MC/DC0%0/1
$_->{"kind"} // ""
$_->{"kind"}
MC/DC0%0/1
$g->{'rules'} || []
$g->{'rules'}
Truth table50%1/2
A
A= $_->{"kind"}
Aresult
11
00
Truth table50%1/2
A
A= $g->{'rules'}
Aresult
11
00
637 1 my $passed = grep { $_->{passed} } @$rules;
638 1 ▶ $score = @$rules ? 0 + sprintf( '%.4f', $passed / @$rules ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$rules ? : 1 0 1
639 1 ▶ $diff = [ map { +{ path => $_->{path}, before => $_->{before}, after => $_->{after} } } @{ $g->{diff} || [] } ];
Condition50%1/2
$g->{'diff'} || []
l!l
10
MC/DC0%0/1
$g->{'diff'} || []
$g->{'diff'}
Truth table50%1/2
A
A= $g->{'diff'}
Aresult
11
00
640 1 ▶ $gaps = [ map { +{ call => $_->{index}, tool => $_->{tool}, gap => $_->{gap} } } @{ $g->{sim_gaps} || [] } ];
Condition50%1/2
$g->{'sim_gaps'} || []
l!l
10
MC/DC0%0/1
$g->{'sim_gaps'} || []
$g->{'sim_gaps'}
Truth table50%1/2
A
A= $g->{'sim_gaps'}
Aresult
11
00
641 1 for my $gap ( @$gaps ) {
642 1 ▶ my $call = defined $gap->{call} ? $calls[ $gap->{call} ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $gap->{'call'} ? : 1 0 1
643 1 ▶ next unless $call;
Branch: 1 branch
BranchTrueFalseTotal
unless $call 0 1 1
644 1 $call->{tool} = $gap->{tool};
645 1 $call->{sim_gap} = $gap->{gap};
646 }
647 }
648 else {
649 5 ▶ $score = $exceeded ? undef : $c->{score};
Branch: 1 branch
BranchTrueFalseTotal
$exceeded ? : 2 3 5
650 5 ▶ $gaps = [ map { +{ call => undef, tool => undef, gap => $_ } } @{ $c->{sim_gaps} || [] } ];
Condition50%1/2
$c->{'sim_gaps'} || []
l!l
50
MC/DC0%0/1
$c->{'sim_gaps'} || []
$c->{'sim_gaps'}
Truth table50%1/2
A
A= $c->{'sim_gaps'}
Aresult
11
00
651 }
652 6 ▶ my $tok = sub { my ( $v ) = @_; return $v ? $v : undef };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 12 6 18
653 return {
654 repetition => $n,
655 seed => $repeat > 1 ? $n : undef,
656 status => $status,
657 score => $score,
658 error => undef,
659 finish_reason => undef,
660 duration_ms => $c->{duration_ms},
661 rules => $rules,
662 diff => $diff,
663 14 ▶ turns => [ map { +{ map { $_ => undef } qw( input_tokens output_tokens reasoning_tokens duration_ms finish_reason calls ) } }
Condition50%1/2
$c->{'turns'} || 0
l!l
60
MC/DC0%0/1
$c->{'turns'} || 0
$c->{'turns'}
Truth table50%1/2
A
A= $c->{'turns'}
Aresult
11
00
664 1 .. ( $c->{turns} || 0 ) ],
665 tokens => {
666 input => $tok->( $c->{prompt_tokens} ),
667 output => $tok->( $c->{completion_tokens} ),
668 reasoning => undef,
669 input_max => $tok->( $c->{prompt_tokens_max} ),
670 },
671 calls => \@calls,
672 sim_gaps => $gaps,
673 forbidden_calls => $c->{forbidden_calls},
674 injection_held => $c->{injection_held},
675 6 ▶ transcript => undef,
Branch: 1 branch
BranchTrueFalseTotal
$repeat > 1 ? : 6 0 6
676 };
677 }
678  
679 27 __PACKAGE__->meta->make_immutable;
680  
681  
682 27 1;
683  
684 __END__
« blib/lib/Langertha/Holmgang/Batch.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/RouterOS.pm »