blib/lib/Langertha/Holmgang/CLI.pm

filter: Statementstmt 97.2% 391 / 402 Branchbran 84.7% 183 / 216 Conditioncond 70.7% 70 / 99 MC/DCmcdc 47.3% 27 / 57 Subroutinesub 98.0% 50 / 51 Podpod 50.0% 6 / 12 totaltotal 86.8% 727 / 837 CC 161 SCAR 27.8
CC
161
Cov
90%
cmd_run
36.5
_target
28.4
cmd_export_yaml
20.1
CRAP 16.1
« blib/lib/Langertha/Holmgang/Sim/Denken.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Sehen.pm »
1 package Langertha::Holmgang::CLI;
2 # ABSTRACT: The holmgang command: lint suites, run them against a Langertha engine, evaluate reports
3  
4 16 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Module::Runtime qw( use_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use Langertha::Holmgang::Batch;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 16 ▶use Langertha::Holmgang::Evaluation;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 16 ▶use Langertha::Holmgang::Loader;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 16 ▶use Langertha::Holmgang::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 16 ▶use Langertha::Holmgang::Runner;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 16 ▶use Langertha::Holmgang::Target;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 16 our $VERSION = '0.001';
20  
21  
22 16 has out => ( is => 'ro', lazy_build => 1 );
23  
24 2 ▶sub _build_out { \*STDOUT }
Subroutine _build_out: called CC=1 SCAR=0.0
25  
26  
27 16 has err => ( is => 'ro', lazy_build => 1 );
28  
29 1 ▶sub _build_err { \*STDERR }
Subroutine _build_err: called CC=1 SCAR=0.0
30  
31  
32 16 has loader => ( is => 'ro', lazy_build => 1 );
33  
34 13 ▶sub _build_loader { $_[0]->loader_class->new }
Subroutine _build_loader: called CC=1 SCAR=0.0
35  
36  
37 16 has checkpoint_seconds => ( is => 'ro', default => 10 );
38  
39  
40 13 ▶sub loader_class { 'Langertha::Holmgang::Loader' }
Subroutine loader_class: called CC=1 SCAR=0.0
Pod undocumented
41 24 ▶sub runner_class { 'Langertha::Holmgang::Runner' }
Subroutine runner_class: called CC=1 SCAR=0.0
Pod undocumented
42 73 ▶sub target_class { 'Langertha::Holmgang::Target' }
Subroutine target_class: called CC=1 SCAR=0.0
Pod undocumented
43 26 ▶sub report_class { 'Langertha::Holmgang::Report' }
Subroutine report_class: called CC=1 SCAR=0.0
Pod undocumented
44 43 ▶sub evaluation_class { 'Langertha::Holmgang::Evaluation' }
Subroutine evaluation_class: called CC=1 SCAR=0.0
Pod undocumented
45 35 ▶sub batch_class { 'Langertha::Holmgang::Batch' }
Subroutine batch_class: called CC=1 SCAR=0.0
Pod undocumented
46  
47 # the statuses of a result the target gave no answer for (ADR 0006)
48 16 my %NO_ANSWER = map { $_ => 1 } qw( error context_exceeded no_vision );
49  
50 # the targets that need no network and no key (ADR 0009)
51 16 my %MOCK = ( 'mock-solution' => 'solution', 'mock-text' => 'text' );
52  
53 16 my $JSON = JSON::MaybeXS->new( utf8 => 0, canonical => 1, allow_nonref => 1 );
54  
55 #### Plumbing
56  
57 168 ▶sub _say { my ( $self, @l ) = @_; print { $self->out } map { $_."\n" } @l; return }
Subroutine _say: called CC=1 SCAR=0.0
58  
59 45 ▶sub _usage_error {
Subroutine _usage_error: called CC=1 SCAR=0.0
60 45 my ( $self, $msg ) = @_;
61 45 print { $self->err } 'holmgang: '.$msg."\n", "Try 'holmgang help'.\n";
62 45 return 2;
63 }
64  
65 # Every die text the CLI relays goes through here (k41): a Path::Tiny error
66 # down to its reason (the message names the path already, not a temporary file
67 # next to it), no Perl location (Target's rule), no module search path.
68 21 ▶sub _text {
Subroutine _text: called CC=5 SCAR=16.1
69 21 my ( $self, $err ) = @_;
70 21 ▶ my $text = blessed $err && $err->isa('Path::Tiny::Error') ? $err->{err} =~ s/\A.*: //sr
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($err) && $err->isa('Path::Tiny::Error') ? : 5 16 21
builtin::blessed($err) ? : 7 9 16
Condition80%4/5
builtin::blessed($err) and $err->isa("Path::Tiny::Error")
!ll&&!rl&&r
975
$err // ""
l!l
90
MC/DC100%2/2
builtin::blessed($err) and $err->isa("Path::Tiny::Error")
builtin::blessed($err) $err->isa("Path::Tiny::Error")
MC/DC0%0/1
$err // ""
$err
Truth table100%3/3
A and B
A= builtin::blessed($err)B= $err->isa("Path::Tiny::Error")
ABresult
0X0
100
111
Truth table50%1/2
A
A= $err
Aresult
11
00
71 : blessed $err ? "$err"
72 : $err // '';
73 21 $text = $self->target_class->_strip_location($text);
74 21 $text =~ s/\s*\(\@INC (?:contains|entries checked): [^)]*\)//;
75 21 return $text =~ s/\s+\z//r;
76 }
77  
78 96 ▶sub _options {
Subroutine _options: called CC=3 SCAR=11.0
79 96 my ( $self, $args, @spec ) = @_;
80 96 my @warn;
81 96 ▶ local $SIG{__WARN__} = sub { push @warn, $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
82 96 my $p = Getopt::Long::Parser->new( config => [qw( no_ignore_case no_auto_abbrev )] );
83 96 my %o;
84 96 my $ok = $p->getoptionsfromarray( $args, \%o, @spec );
85 96 ▶ return ( undef, join( '', @warn ) =~ s/\s+\z//r || 'bad options' ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 95 96
Condition50%1/2
join('', @warn) =~ s/\s+\z//r || 'bad options'
l!l
10
MC/DC0%0/1
join('', @warn) =~ s/\s+\z//r || 'bad options'
join('', @warn) =~ s/\s+\z//r
Truth table50%1/2
A
A= join('', @warn) =~ s/\s+\z//r
Aresult
11
00
86 95 return ( \%o, undef );
87 }
88  
89 # K=V; the value as JSON when it parses as such, else as written
90 66 ▶sub _pairs {
Subroutine _pairs: called CC=5 SCAR=16.1
91 66 my ( $self, $what, $list ) = @_;
92 66 my %h;
93 66 ▶ for my $p ( @{ $list || [] } ) {
Condition100%2/2
$list || []
l!l
633
MC/DC100%1/1
$list || []
$list
Truth table100%2/2
A
A= $list
Aresult
11
00
94 23 ▶ my ( $k, $v ) = $p =~ /\A([A-Za-z_][A-Za-z0-9_]*)=(.*)\z/s
Branch: 1 branch
BranchTrueFalseTotal
() = $p =~ /\A([A-Za-z_][A-Za-z0-9_]*)=(.*)\z/s or return undef, $what . ' expects KEY=VALUE, got: ' . $p 22 1 23
95 or return ( undef, $what.' expects KEY=VALUE, got: '.$p );
96 22 my $d = eval { $JSON->decode($v) };
97 22 ▶ $h{$k} = $@ ? $v : $d;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 5 17 22
98 }
99 65 return ( \%h, undef );
100 }
101  
102 99 ▶sub run {
Subroutine run: called CC=4 SCAR=13.9
Pod documented
103 99 my ( $self, @argv ) = @_;
104 99 my $cmd = shift @argv;
105 99 ▶ return $self->_usage_error('a command is needed: lint, run, report or export-yaml') unless defined $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cmd 2 97 99
106 97 ▶ return $self->help if $cmd =~ /\A(?:help|--help|-h)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd =~ /\A(?:help|--help|-h)\z/ 1 96 97
107 96 ▶ my $method = { lint => 'cmd_lint', run => 'cmd_run', report => 'cmd_report', 'export-yaml' => 'cmd_export_yaml' }->{$cmd}
Branch: 1 branch
BranchTrueFalseTotal
my $method = {"lint", "cmd_lint", "run", "cmd_run", "report", "cmd_report", "export-yaml", "cmd_export_yaml"}->{$cmd} or return $self->_usage_error('unknown command: ' . $cmd) 96 0 96
108 or return $self->_usage_error( 'unknown command: '.$cmd );
109 96 return $self->$method(@argv);
110 }
111  
112  
113 1 ▶sub help {
Subroutine help: called CC=1 SCAR=0.0
Pod documented
114 1 my ( $self ) = @_;
115 1 $self->_say(
116 'usage: holmgang lint <suite-dir>... [--seed ID=N]...',
117 ' holmgang run --suite <dir>... --target <engine|mock-solution|mock-text>',
118 ' [--model M] [--url U] [--option K=V]... [--label L]',
119 ' [--variant [NAME:]K=V]... [--repeat N] [--concurrency N]',
120 ' [--resume earlier.json] [--report out.json] [--seed ID=N]...',
121 ' holmgang report <report.json>... [--by topic] [--format text|markdown|json] [--suite <dir>]...',
122 ' holmgang export-yaml <suite-dir>... --out <dir> [--seed ID=N]...',
123 '',
124 'Exit codes: 0 ok, 1 a suite refused, a verdict not ok or no case answered, 2 usage or setup error.',
125 'Keys come from the engine\'s environment variable (e.g. LANGERTHA_OPENAI_API_KEY), never from the command line.',
126 );
127 1 return 0;
128 }
129  
130  
131 #### lint
132  
133 # a suite directory: suite.yaml (format 2) or suite.pl (the DSL)
134 157 ▶sub _is_suite { my ( $p ) = @_; return -f $p->child('suite.yaml') || -f $p->child('suite.pl') }
Subroutine _is_suite: called CC=2 SCAR=6.9
Condition100%3/3
-f $p->child('suite.yaml') || -f $p->child('suite.pl')
l!l&&r!l&&!r
1192216
MC/DC100%2/2
-f $p->child('suite.yaml') || -f $p->child('suite.pl')
-f $p->child('suite.yaml') -f $p->child('suite.pl')
Truth table100%3/3
A || B
A= -f $p->child('suite.yaml')B= -f $p->child('suite.pl')
ABresult
1X1
011
000
135  
136 # the suite directories an argument names: itself, or its subdirectories with a suite
137 20 ▶sub _suite_dirs {
Subroutine _suite_dirs: called CC=4 SCAR=14.0
138 20 my ( $self, $arg ) = @_;
139 20 my $p = path($arg);
140 20 ▶ return unless $p->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $p->is_dir 1 19 20
141 19 ▶ return ( "$p" ) if _is_suite($p);
Branch: 1 branch
BranchTrueFalseTotal
if _is_suite($p) 6 13 19
142 13 ▶ return map { "$_" } sort { $a->basename cmp $b->basename } grep { $_->is_dir && _is_suite($_) } $p->children;
Condition33%1/3
$_->is_dir && _is_suite($_)
!ll&&!rl&&r
0029
MC/DC0%0/2
$_->is_dir && _is_suite($_)
$_->is_dir _is_suite($_)
Truth table33%1/3
A && B
A= $_->is_dirB= _is_suite($_)
ABresult
0X0
100
111
143 }
144  
145 # --seed ID=N (k51): the loader's seed override for the DSL suites among
146 # @dirs. ( $loader ) -- this CLI's own without --seed -- or ( undef, $error )
147 56 ▶sub _seeded_loader {
Subroutine _seeded_loader: called CC=9 SCAR=22.0
148 56 my ( $self, $list, $dirs ) = @_;
149 56 ▶ return ( $self->loader ) unless @{ $list || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$list or [];} 46 10 56
Condition100%2/2
$list || []
l!l
1046
MC/DC100%1/1
$list || []
$list
Truth table100%2/2
A
A= $list
Aresult
11
00
150 10 my %dsl = map { ( path($_)->basename => 1 ) } grep { -f path($_)->child('suite.pl') } @$dirs;
151 10 my %seeds;
152 10 for my $p ( @$list ) {
153 11 ▶ my ( $id, $n ) = $p =~ /\A([^=]+)=([0-9]+)\z/
Branch: 1 branch
BranchTrueFalseTotal
() = $p =~ /\A([^=]+)=([0-9]+)\z/ or return undef, '--seed expects SUITE-ID=N, got: ' . $p 9 2 11
154 or return ( undef, '--seed expects SUITE-ID=N, got: '.$p );
155 9 ▶ return ( undef, '--seed '.$id.': the seed is an integer from 0 to 4294967295' )
Branch: 1 branch
BranchTrueFalseTotal
if length $n > 10 or $n > 4294967295 1 8 9
Condition66%2/3
length $n > 10 or $n > 4294967295
l!l&&r!l&&!r
018
MC/DC50%1/2
length $n > 10 or $n > 4294967295
length $n > 10 $n > 4294967295
Truth table66%2/3
A or B
A= length $n > 10B= $n > 4294967295
ABresult
1X1
011
000
156 if length $n > 10 || $n > 4294967295;
157 8 ▶ return ( undef, '--seed '.$id.': given twice' ) if exists $seeds{$id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $seeds{$id} 1 7 8
158 return ( undef, '--seed '.$id.': no suite in the case DSL (suite.pl) with this id in this command' )
159 7 ▶ unless $dsl{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $dsl{$id} 3 4 7
160 4 $seeds{$id} = 0 + $n;
161 }
162 3 my $l = $self->loader;
163 12 return ( ref($l)->new( ( map { ( $_ => $l->$_ ) } qw( simulators haystack structure lint ) ),
164 3 seeds => { %{ $l->seeds }, %seeds } ) );
165 }
166  
167 18 ▶sub cmd_lint {
Subroutine cmd_lint: called CC=11 SCAR=24.0
Pod documented
168 18 my ( $self, @argv ) = @_;
169 18 my ( $o, $bad ) = $self->_options( \@argv, 'seed=s@' );
170 18 ▶ return $self->_usage_error($bad) if $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad 1 17 18
171 17 ▶ return $self->_usage_error('lint needs at least one suite directory') unless @argv;
Branch: 1 branch
BranchTrueFalseTotal
unless @argv 1 16 17
172 16 my @dirs;
173 16 for my $arg ( @argv ) {
174 16 my @d = $self->_suite_dirs($arg);
175 16 ▶ return $self->_usage_error( 'no suite at or below '.$arg ) unless @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 1 15 16
176 15 push @dirs, @d;
177 }
178 15 my ( $loader, $lbad ) = $self->_seeded_loader( $o->{seed}, \@dirs );
179 15 ▶ return $self->_usage_error($lbad) unless $loader;
Branch: 1 branch
BranchTrueFalseTotal
unless $loader 6 9 15
180 9 my ( $ok, $refused ) = ( 0, 0 );
181 9 for my $dir ( @dirs ) {
182 17 my $suite = eval { $loader->load($dir) };
183 17 ▶ if ( $suite ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suite) { } 14 3 17
184 14 $ok++;
185 14 my @cases = @{ $suite->cases };
186 14 ▶ $self->_say( 'ok '.$suite->id.' ('.scalar(@cases).' case'.( @cases == 1 ? '' : 's' ).')', map { ' ok '.$_->id } @cases );
Branch: 1 branch
BranchTrueFalseTotal
@cases == 1 ? : 8 6 14
187 }
188 else {
189 3 $refused++;
190 3 $self->_say( 'FAIL '.path($dir)->basename, ' '.$self->_text($@) );
191 }
192 }
193 9 ▶ $self->_say( scalar(@dirs).' suite'.( @dirs == 1 ? '' : 's' ).': '.$ok.' ok, '.$refused.' refused' );
Branch: 1 branch
BranchTrueFalseTotal
@dirs == 1 ? : 5 4 9
194 9 ▶ return $refused ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$refused ? : 3 6 9
195 }
196  
197  
198 #### export-yaml
199  
200 6 ▶sub cmd_export_yaml {
Subroutine cmd_export_yaml: called CC=18 SCAR=30.0
Pod documented
201 6 my ( $self, @argv ) = @_;
202 6 my ( $o, $bad ) = $self->_options( \@argv, 'out=s', 'seed=s@' );
203 6 ▶ return $self->_usage_error($bad) if $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad 0 6 6
204 return $self->_usage_error('export-yaml needs --out, the directory the suites are written into')
205 6 ▶ unless defined $o->{out} && length $o->{out};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$o{"out"} and length $$o{"out"} 2 4 6
Condition66%2/3
defined $$o{"out"} and length $$o{"out"}
!ll&&!rl&&r
204
MC/DC50%1/2
defined $$o{"out"} and length $$o{"out"}
defined $$o{"out"} length $$o{"out"}
Truth table66%2/3
A and B
A= defined $$o{"out"}B= length $$o{"out"}
ABresult
0X0
100
111
206 4 ▶ return $self->_usage_error('export-yaml needs at least one suite directory') unless @argv;
Branch: 1 branch
BranchTrueFalseTotal
unless @argv 0 4 4
207 4 my @dirs;
208 4 for my $arg ( @argv ) {
209 4 my @d = $self->_suite_dirs($arg);
210 4 ▶ return $self->_usage_error( 'no suite at or below '.$arg ) unless @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 4 4
211 4 push @dirs, @d;
212 }
213 4 my @dsl = grep { -f path($_)->child('suite.pl') } @dirs;
214 4 ▶ return $self->_usage_error( 'no suite in the case DSL (suite.pl) among: '.join( ' ', @argv ) ) unless @dsl;
Branch: 1 branch
BranchTrueFalseTotal
unless @dsl 1 3 4
215 3 for my $dir ( @dsl ) {
216 3 my $to = path( $o->{out}, path($dir)->basename );
217 3 ▶ return $self->_usage_error( 'exists already, nothing is overwritten: '.$to ) if -e $to || -l $to;
Branch: 1 branch
BranchTrueFalseTotal
if -e $to or -l $to 1 2 3
Condition66%2/3
-e $to or -l $to
l!l&&r!l&&!r
102
MC/DC50%1/2
-e $to or -l $to
-e $to -l $to
Truth table66%2/3
A or B
A= -e $toB= -l $to
ABresult
1X1
011
000
218 }
219 2 my ( $loader, $lbad ) = $self->_seeded_loader( $o->{seed}, \@dirs );
220 2 ▶ return $self->_usage_error($lbad) unless $loader;
Branch: 1 branch
BranchTrueFalseTotal
unless $loader 0 2 2
221 2 my ( $ok, $refused ) = ( 0, 0 );
222 2 for my $dir ( @dirs ) {
223 3 my $id = path($dir)->basename;
224 3 ▶ unless ( -f path($dir)->child('suite.pl') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f path($dir)->child("suite.pl")) 1 2 3
225 1 $self->_say( 'skip '.$id.' (format 2 already)' );
226 1 next;
227 }
228 2 my $out = eval { $loader->export( $dir, $o->{out} ) };
229 2 ▶ if ( defined $out ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $out) { } 2 0 2
230 2 $ok++;
231 2 my $n = () = path( $out, 'cases' )->children(qr/\.yaml\z/);
232 2 ▶ $self->_say( 'ok '.$id.' ('.$n.' case'.( $n == 1 ? '' : 's' ).') -> '.$out );
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 0 2 2
233 }
234 else {
235 0 $refused++;
236 0 $self->_say( 'FAIL '.$id, ' '.$self->_text($@) );
237 }
238 }
239 2 ▶ $self->_say( scalar(@dsl).' DSL suite'.( @dsl == 1 ? '' : 's' ).': '.$ok.' exported, '.$refused.' refused' );
Branch: 1 branch
BranchTrueFalseTotal
@dsl == 1 ? : 2 0 2
240 2 ▶ return $refused ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$refused ? : 0 2 2
241 }
242  
243  
244 #### run
245  
246 50 ▶sub _load_suites {
Subroutine _load_suites: called CC=6 SCAR=17.9
247 50 my ( $self, $dirs, $loader ) = @_;
248 50 ▶ $loader //= $self->loader;
Condition66%2/3
$loader //= $self->loader
l!l&&r!l&&!r
38120
MC/DC0%0/2
$loader //= $self->loader
$loader $self->loader
Truth table66%2/3
A //= B
A= $loaderB= $self->loader
ABresult
1X1
011
000
249 50 my @suites;
250 50 ▶ for my $arg ( @{ $dirs || [] } ) {
Condition100%2/2
$dirs || []
l!l
4010
MC/DC100%1/1
$dirs || []
$dirs
Truth table100%2/2
A
A= $dirs
Aresult
11
00
251 55 ▶ return ( undef, 'not a suite directory (no suite.yaml or suite.pl): '.$arg ) unless _is_suite( path($arg) );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_suite(path($arg)) 2 53 55
252 53 my $s = eval { $loader->load($arg) };
253 53 ▶ return ( undef, 'suite '.$arg.' does not load: '.$self->_text($@) ) unless $s;
Branch: 1 branch
BranchTrueFalseTotal
unless $s 1 52 53
254 52 push @suites, $s;
255 }
256 47 return ( \@suites, undef );
257 }
258  
259 43 ▶sub _thresholds {
Subroutine _thresholds: called CC=1 SCAR=0.0
260 43 my ( $self, $suites ) = @_;
261 43 return { map { ( $_->id => $_->threshold ) } grep { ref $_->threshold eq 'HASH' } @$suites };
262 }
263  
264 # ( $engine_for, $target_meta ) or ( undef, $error ); $engine_for->( $case, $slot )
265 44 ▶sub _target {
Subroutine _target: called CC=22 SCAR=33.5
266 44 my ( $self, $o ) = @_;
267 44 my $name = $o->{target};
268 44 ▶ return ( undef, 'run needs --target (an engine name such as OpenAI, or mock-solution / mock-text)' )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 1 43 44
Condition66%2/3
defined $name and length $name
!ll&&!rl&&r
1043
MC/DC50%1/2
defined $name and length $name
defined $name length $name
Truth table66%2/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
269 unless defined $name && length $name;
270 43 ▶ if ( my $mode = $MOCK{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mode = $MOCK{$name}) 25 18 43
271 return ( undef, '--model, --url and --option do not apply to '.$name )
272 25 ▶ if defined $o->{model} || defined $o->{url} || @{ $o->{option} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if defined $$o{"model"} or defined $$o{"url"} or @{$$o{"option"} or [];} 1 24 25
Condition62%5/8
defined $$o{"model"} or defined $$o{"url"} or @{$$o{"option"} or [];}
l!l&&r!l&&!r
1024
defined $$o{"model"} or defined $$o{"url"}
l!l&&r!l&&!r
1024
$$o{'option'} || []
l!l
024
MC/DC33%1/3
defined $$o{"model"} or defined $$o{"url"} or @{$$o{"option"} or [];}
defined $$o{"model"} defined $$o{"url"} @{$$o{"option"} or [];}
MC/DC0%0/1
$$o{'option'} || []
$$o{'option'}
Truth table50%2/4
A or B or C
A= defined $$o{"model"}B= defined $$o{"url"}C= @{$$o{"option"} or [];}
ABCresult
1XX1
01X1
0011
0000
Truth table50%1/2
A
A= $$o{'option'}
Aresult
11
00
273 24 my $runner = $self->runner_class;
274 77 ▶ return ( sub { $runner->mock_engine( $_[0], $mode ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
275 24 ▶ { label => $o->{label} // $name, engine => 'Virtual', model => undef, url => undef } );
Condition33%1/3
$$o{"label"} // $name
l!l&&r!l&&!r
0240
MC/DC0%0/2
$$o{"label"} // $name
$$o{"label"} $name
Truth table33%1/3
A // B
A= $$o{"label"}B= $name
ABresult
1X1
011
000
276 }
277 18 ▶ return ( undef, 'not an engine name: '.$name ) unless $name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/ 0 18 18
278 18 my ( $opt, $bad ) = $self->_pairs( '--option', $o->{option} );
279 18 ▶ return ( undef, $bad ) if $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad 0 18 18
280 return ( undef, '--option api_key is refused: the key comes from the engine\'s environment variable, never from the command line' )
281 18 ▶ if exists $opt->{api_key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$opt{"api_key"} 1 17 18
282 17 ▶ $opt->{model} = $o->{model} if defined $o->{model};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$o{"model"} 1 16 17
283 17 ▶ $opt->{url} = $o->{url} if defined $o->{url};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$o{"url"} 0 17 17
284 17 ▶ my $class = $name =~ /::/ ? $name : 'Langertha::Engine::'.$name;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /::/ ? : 5 12 17
285 # a notice of the engine while it is built (a setting it drops): to stderr,
286 # cleaned as a relayed error (k42)
287 17 my @warn;
288 17 my $engine = do {
289 17 ▶ local $SIG{__WARN__} = sub { push @warn, $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
290 17 eval { use_module($class)->new(%$opt) };
291 };
292 17 print { $self->err } map { 'holmgang: '.$self->target_class->scrub( $self->_text($_) )."\n" } @warn;
293 17 ▶ return ( undef, 'target '.$name.' does not build: '.$self->target_class->scrub( $self->_text($@) ) ) unless $engine;
Branch: 1 branch
BranchTrueFalseTotal
unless $engine 2 15 17
294 15 ▶ return ( undef, 'target '.$name.' is no chat engine with tool calling (chat_f, format_tool_results)' )
Branch: 1 branch
BranchTrueFalseTotal
unless $engine->can("chat_f") and $engine->can("format_tool_results") 0 15 15
Condition33%1/3
$engine->can("chat_f") and $engine->can("format_tool_results")
!ll&&!rl&&r
0015
MC/DC0%0/2
$engine->can("chat_f") and $engine->can("format_tool_results")
$engine->can("chat_f") $engine->can("format_tool_results")
Truth table33%1/3
A and B
A= $engine->can("chat_f")B= $engine->can("format_tool_results")
ABresult
0X0
100
111
295 unless $engine->can('chat_f') && $engine->can('format_tool_results');
296 15 ▶ my $model = $engine->can('model') ? eval { $engine->model } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$engine->can('model') ? : 15 0 15
297 15 ▶ my $url = $engine->can('url') ? eval { $engine->url } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$engine->can('url') ? : 15 0 15
298 15 my $short = $class =~ s/\ALangertha::Engine:://r;
299 # one engine per concurrency slot, each with its own connection: the first
300 # is the one built above, the others are built alike when a slot first
301 # needs one -- their notices were said with the first
302 15 my @engines = ( $engine );
303 43 ▶ my $engine_for = sub {
Subroutine __ANON__: called CC=3 SCAR=15.1
304 43 my ( $case, $slot ) = @_;
305 43 ▶ return $engines[ $slot // 0 ] //= do {
Condition40%2/5
$engines[$slot // 0] //= do { local $SIG{"__WARN__"} = sub { } ; &use_module($class)->new(%$opt) }
l!l&&r!l&&!r
4300
$slot // 0
l!l
430
MC/DC0%0/2
$engines[$slot // 0] //= do { local $SIG{"__WARN__"} = sub { } ; &use_module($class)->new(%$opt) }
$engines[$slot // 0] do { local $SIG{"__WARN__"} = sub { } ; &use_module($class)->new(%$opt) }
MC/DC0%0/1
$slot // 0
$slot
Truth table33%1/3
A //= B
A= $engines[$slot // 0]B= do { local $SIG{"__WARN__"} = sub { } ; &use_module($class)->new(%$opt) }
ABresult
1X1
011
000
Truth table50%1/2
A
A= $slot
Aresult
11
00
306 0 ▶ local $SIG{__WARN__} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
307 0 use_module($class)->new(%$opt);
308 };
309 15 };
310 return ( $engine_for,
311 15 ▶ { label => $o->{label} // $model // $short, engine => $short, model => $model, url => $url } );
Condition50%3/6
($$o{"label"} // $model) // $short
l!l&&r!l&&!r
1500
$$o{"label"} // $model
l!l&&r!l&&!r
2130
MC/DC0%0/3
($$o{"label"} // $model) // $short
$$o{"label"} $model $short
Truth table50%2/4
A // B // C
A= $$o{"label"}B= $modelC= $short
ABCresult
1XX1
01X1
0011
0000
312 }
313  
314 # --variant K=V adds to the unnamed variant, --variant NAME:K=V to the variant
315 # NAME, --variant NAME: names a variant without settings. ( \@variants ) or
316 # ( undef, $error ); each variant { name, settings } with its settings checked
317 47 ▶sub _variants {
Subroutine _variants: called CC=16 SCAR=27.7
318 47 my ( $self, $list ) = @_;
319 47 my ( %named, @order, @plain );
320 47 ▶ for my $p ( @{ $list || [] } ) {
Condition100%2/2
$list || []
l!l
641
MC/DC100%1/1
$list || []
$list
Truth table100%2/2
A
A= $list
Aresult
11
00
321 9 ▶ if ( my ( $name, $rest ) = $p =~ /\A([A-Za-z0-9][A-Za-z0-9_.+-]*):(.*)\z/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $p =~ /\A([A-Za-z0-9][A-Za-z0-9_.+-]*):(.*)\z/s) { } 4 5 9
322 4 ▶ push @order, $name unless $named{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $named{$name} 3 1 4
323 4 ▶ $named{$name} //= [];
Condition100%2/2
$named{$name} //= []
l!l
13
MC/DC100%1/1
$named{$name} //= []
$named{$name}
Truth table100%2/2
A
A= $named{$name}
Aresult
11
00
324 4 ▶ push @{ $named{$name} }, $rest if length $rest;
Branch: 1 branch
BranchTrueFalseTotal
if length $rest 3 1 4
325 }
326 else {
327 5 push @plain, $p;
328 }
329 }
330 47 my @variants;
331 47 ▶ for my $group ( ( @plain || !@order ? [ undef, \@plain ] : () ), map { [ $_, $named{$_} ] } @order ) {
Branch: 1 branch
BranchTrueFalseTotal
@plain || !@order ? : 45 2 47
Condition100%3/3
@plain or not @order
l!l&&r!l&&!r
4412
MC/DC100%2/2
@plain or not @order
@plain not @order
Truth table100%3/3
A or not(B)
A= @plainB= not @order
ABresult
1X1
011
000
332 48 my ( $name, $pairs ) = @$group;
333 48 my ( $settings, $bad ) = $self->_pairs( '--variant', $pairs );
334 48 ▶ return ( undef, $bad ) if $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad 1 47 48
335 47 my $checked = eval { $self->target_class->check_variant($settings) };
336 47 ▶ return ( undef, '--variant'.( defined $name ? ' '.$name : '' ).': '.$self->_text($@) ) unless $checked;
Branch: 2 branches
BranchTrueFalseTotal
unless $checked 2 45 47
defined $name ? : 0 2 2
337 $name //= %$checked
338 45 ▶ ? join( ',', map { $_.'='.$JSON->encode( $checked->{$_} ) =~ s/\A"(.*)"\z/$1/sr } sort keys %$checked )
Branch: 1 branch
BranchTrueFalseTotal
%$checked ? : 1 41 42
Condition100%2/2
$name //= %$checked ? join(",", map({$_ . '=' . $JSON->encode($$checked{$_}) =~ s/\A"(.*)"\z/$1/rs;} sort(keys %$checked))) : "default"
l!l
342
MC/DC100%1/1
$name //= %$checked ? join(",", map({$_ . '=' . $JSON->encode($$checked{$_}) =~ s/\A"(.*)"\z/$1/rs;} sort(keys %$checked))) : "default"
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
339 : 'default';
340 45 ▶ return ( undef, '--variant: the variant '.$name.' is named twice' ) if grep { $_->{name} eq $name } @variants;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$$_{"name"} eq $name;} @variants 0 45 45
341 45 push @variants, { name => $name, settings => $checked };
342 }
343 44 return ( \@variants, undef );
344 }
345  
346 50 ▶sub cmd_run {
Subroutine cmd_run: called CC=36 SCAR=36.0
Pod documented
347 50 my ( $self, @argv ) = @_;
348 50 my ( $o, $bad ) = $self->_options( \@argv,
349 'suite=s@', 'target=s', 'model=s', 'url=s', 'option=s@', 'label=s', 'variant=s@', 'repeat=i',
350 'concurrency=i', 'resume=s', 'report=s', 'seed=s@' );
351 50 ▶ return $self->_usage_error($bad) if $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad 0 50 50
352 50 ▶ return $self->_usage_error( 'unexpected argument: '.$argv[0] ) if @argv;
Branch: 1 branch
BranchTrueFalseTotal
if @argv 0 50 50
353 50 ▶ return $self->_usage_error('run needs at least one --suite') unless @{ $o->{suite} || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$$o{"suite"} or [];} 1 49 50
Condition100%2/2
$$o{'suite'} || []
l!l
491
MC/DC100%1/1
$$o{'suite'} || []
$$o{'suite'}
Truth table100%2/2
A
A= $$o{'suite'}
Aresult
11
00
354 return $self->_usage_error('--repeat must be between 1 and 100')
355 49 ▶ if defined $o->{repeat} && ( $o->{repeat} < 1 || $o->{repeat} > 100 );
Branch: 1 branch
BranchTrueFalseTotal
if defined $$o{"repeat"} and $$o{"repeat"} < 1 || $$o{"repeat"} > 100 1 48 49
Condition83%5/6
defined $$o{"repeat"} and $$o{"repeat"} < 1 || $$o{"repeat"} > 100
!ll&&!rl&&r
35131
$$o{"repeat"} < 1 or $$o{"repeat"} > 100
l!l&&r!l&&!r
1013
MC/DC66%2/3
defined $$o{"repeat"} and $$o{"repeat"} < 1 || $$o{"repeat"} > 100
defined $$o{"repeat"} $$o{"repeat"} < 1 $$o{"repeat"} > 100
Truth table75%3/4
A and B or C
A= defined $$o{"repeat"}B= $$o{"repeat"} < 1C= $$o{"repeat"} > 100
ABCresult
0XX0
1000
11X1
1011
356 return $self->_usage_error('--concurrency must be between 1 and 64')
357 48 ▶ if defined $o->{concurrency} && ( $o->{concurrency} < 1 || $o->{concurrency} > 64 );
Branch: 1 branch
BranchTrueFalseTotal
if defined $$o{"concurrency"} and $$o{"concurrency"} < 1 || $$o{"concurrency"} > 64 1 47 48
Condition83%5/6
defined $$o{"concurrency"} and $$o{"concurrency"} < 1 || $$o{"concurrency"} > 64
!ll&&!rl&&r
4611
$$o{"concurrency"} < 1 or $$o{"concurrency"} > 64
l!l&&r!l&&!r
101
MC/DC66%2/3
defined $$o{"concurrency"} and $$o{"concurrency"} < 1 || $$o{"concurrency"} > 64
defined $$o{"concurrency"} $$o{"concurrency"} < 1 $$o{"concurrency"} > 64
Truth table75%3/4
A and B or C
A= defined $$o{"concurrency"}B= $$o{"concurrency"} < 1C= $$o{"concurrency"} > 64
ABCresult
0XX0
1000
11X1
1011
358 47 my ( $variants, $vbad ) = $self->_variants( $o->{variant} );
359 47 ▶ return $self->_usage_error($vbad) if $vbad;
Branch: 1 branch
BranchTrueFalseTotal
if $vbad 3 44 47
360 44 my ( $engine_for, $target ) = $self->_target($o);
361 44 ▶ return $self->_usage_error($target) unless $engine_for;
Branch: 1 branch
BranchTrueFalseTotal
unless $engine_for 5 39 44
362 39 my ( $loader, $lbad ) = $self->_seeded_loader( $o->{seed}, [ grep { _is_suite( path($_) ) } @{ $o->{suite} } ] );
363 39 ▶ return $self->_usage_error($lbad) unless $loader;
Branch: 1 branch
BranchTrueFalseTotal
unless $loader 1 38 39
364 38 my ( $suites, $sbad ) = $self->_load_suites( $o->{suite}, $loader );
365 38 ▶ return $self->_usage_error($sbad) if $sbad;
Branch: 1 branch
BranchTrueFalseTotal
if $sbad 2 36 38
366 36 my $resume;
367 36 ▶ if ( defined $o->{resume} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$o{"resume"}) 3 33 36
368 3 $resume = eval { $self->report_class->read( $o->{resume} ) };
369 3 ▶ return $self->_usage_error( 'report '.$o->{resume}.' does not read: '.$self->_text($@) ) unless $resume;
Branch: 1 branch
BranchTrueFalseTotal
unless $resume 1 2 3
370 }
371  
372 35 my $several = @$variants > 1;
373 35 my $batch;
374 35 my $last_write = time;
375 84 ▶ my $on_event = sub {
Subroutine __ANON__: called CC=10 SCAR=23.3
376 84 my ( $e ) = @_;
377 84 ▶ my $at = ( $several ? $e->{variant}.' ' : '' ).$e->{suite}->id;
Branch: 1 branch
BranchTrueFalseTotal
$several ? : 2 82 84
378 84 ▶ if ( $e->{type} eq 'result' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($$e{'type'} eq 'result') { } 77 7 84
elsif ($$e{'type'} eq 'vision') { } 5 2 7
elsif ($$e{'type'} eq 'aborted') { } 2 0 2
379 77 $self->_say( $at.' '.$e->{case}->id.' #'.$e->{repetition}.' '.$e->{result}{status} );
380 77 ▶ $self->_checkpoint( $batch, $o->{report}, \$last_write ) if defined $o->{report};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$o{"report"} 36 41 77
381 }
382 elsif ( $e->{type} eq 'vision' ) {
383 5 my $check = $e->{check};
384 5 my $no_vision = $check->{no_vision};
385 $self->_say( $at.' vision check: '.(
386 defined $no_vision ? 'no_vision -- '.$self->_one_line($no_vision)
387 : defined $check->{added_tokens} ? 'seen (the image added '.$check->{added_tokens}.' input tokens)'
388 5 ▶ : 'not ruled out -- '.$self->_one_line( $check->{note} // 'no check decided' ) ) );
Branch: 2 branches
BranchTrueFalseTotal
defined $no_vision ? : 1 4 5
defined $$check{'added_tokens'} ? : 0 4 4
Condition50%1/2
$$check{"note"} // "no check decided"
l!l
40
MC/DC0%0/1
$$check{"note"} // "no check decided"
$$check{"note"}
Truth table50%1/2
A
A= $$check{"note"}
Aresult
11
00
389 }
390 elsif ( $e->{type} eq 'aborted' ) {
391 $self->_say( $e->{case}
392 ? $at.' '.$e->{case}->id.' #'.$e->{repetition}.' aborted: '.$e->{error}
393 2 ▶ : $at.' vision check aborted: '.$e->{error} );
Branch: 1 branch
BranchTrueFalseTotal
$$e{'case'} ? : 2 0 2
394 }
395 84 return;
396 35 };
397 35 $batch = eval {
398 $self->batch_class->new(
399 suites => $suites,
400 targets => [ {
401 target => $target,
402 engine => $engine_for,
403 variants => $variants,
404 concurrency => $o->{concurrency} // 1,
405 } ],
406 35 ▶ ( defined $o->{repeat} ? ( repeat => $o->{repeat} ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
defined $$o{'repeat'} ? : 13 22 35
$resume ? : 2 33 35
Condition100%2/2
$$o{"concurrency"} // 1
l!l
134
MC/DC100%1/1
$$o{"concurrency"} // 1
$$o{"concurrency"}
Truth table100%2/2
A
A= $$o{"concurrency"}
Aresult
11
00
407 ( $resume ? ( resume => $resume ) : () ),
408 on_event => $on_event,
409 );
410 };
411 35 ▶ return $self->_usage_error( $self->target_class->scrub( $self->_text($@) ) ) unless $batch;
Branch: 1 branch
BranchTrueFalseTotal
unless $batch 2 33 35
412  
413 # a signal cancels: no further case starts, the cases in play finish and
414 # the report is written; a second signal ends the process at once
415 1 ▶ my $cancel = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
416 1 my ( $sig ) = @_;
417 1 $SIG{$sig} = 'DEFAULT';
418 1 $batch->cancel;
419 1 print { $self->err } 'holmgang: '.$sig.': cancelling -- no further case starts, the cases in play finish'."\n";
420 33 };
421 33 my $report = do {
422 33 local @SIG{qw( INT TERM )} = ( $cancel, $cancel );
423 33 eval { $batch->run };
424 };
425 33 ▶ return $self->_usage_error( 'the batch failed: '.$self->target_class->scrub( $self->_text($@) ) ) unless $report;
Branch: 1 branch
BranchTrueFalseTotal
unless $report 0 33 33
426 33 ▶ if ( defined $o->{report} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$o{"report"}) 21 12 33
427 21 eval { $report->write( $o->{report} ); 1 }
428 21 ▶ or return $self->_usage_error( 'report '.$o->{report}.' not written: '.$self->_text($@) );
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $report->write($$o{"report"}); 1 } } or return $self->_usage_error('report ' . $$o{"report"} . ' not written: ' . $self->_text($@)) 20 1 21
429 }
430 32 my $ev = $self->evaluation_class->new( report => $report, thresholds => $self->_thresholds($suites) );
431 32 $self->_say( '', $ev->to_text );
432 32 ▶ $self->_say( 'report: '.$o->{report} ) if defined $o->{report};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$o{"report"} 20 12 32
433 # an aborted or cancelled run (k15)
434 32 ▶ return 2 if grep { $_->{status} ne 'complete' } @{ $report->runs };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$$_{"status"} ne "complete";} @{$report->runs;} 3 29 32
435  
436 # the report holds the results in suite, case and repetition order: the
437 # first error text found is the first of the run (k44)
438 29 my ( @unanswered, @silent, $first_error );
439 29 my $measured = 0;
440 29 for my $run ( @{ $report->runs } ) {
441 45 my @reps = map { @{ $_->{repetitions} } } @{ $run->{cases} };
442 45 ▶ ( $first_error ) = grep { defined && length } map { $_->{error} } @reps unless defined $first_error;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first_error 41 4 45
Condition66%2/3
defined $_ && length $_
!ll&&!rl&&r
58014
MC/DC50%1/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
443 45 my @none = grep { $NO_ANSWER{$_} } map { $_->{status} } @reps;
444 45 push @unanswered, @none;
445 45 $measured += @reps - @none;
446 45 ▶ push @silent, [ ( $several ? $run->{variant}{name}.' ' : '' ).$run->{suite}{id}, $self->_tally(@none) ]
Branch: 2 branches
BranchTrueFalseTotal
if @reps and @reps == @none 9 36 45
$several ? : 0 9 9
Condition66%2/3
@reps and @reps == @none
!ll&&!rl&&r
0369
MC/DC50%1/2
@reps and @reps == @none
@reps @reps == @none
Truth table66%2/3
A and B
A= @repsB= @reps == @none
ABresult
0X0
100
111
447 if @reps && @reps == @none;
448 }
449 # no answer over the whole run: nothing was measured, whatever the verdicts (k42)
450 29 ▶ unless ( $measured ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($measured) 5 24 29
451 5 ▶ print { $self->err } 'holmgang: no case got an answer from the target ('
Branch: 1 branch
BranchTrueFalseTotal
defined $first_error ? : 5 0 5
452 .$self->_tally(@unanswered).')'
453 .( defined $first_error ? '; first: '.$self->_one_line($first_error) : '' )."\n";
454 5 return 1;
455 }
456 24 print { $self->err } 'holmgang: suite '.$_->[0].': no case got an answer from the target ('.$_->[1].')'."\n" for @silent;
457 24 ▶ return ( grep { !$_->{ok} } @{ $ev->verdicts } ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({not $$_{'ok'};} @{$ev->verdicts;}) ? : 5 19 24
458 }
459  
460 # the report as it stands, at most every checkpoint_seconds; a checkpoint
461 # that cannot be written is said once and the run goes on
462 36 ▶sub _checkpoint {
Subroutine _checkpoint: called CC=5 SCAR=28.2
463 36 my ( $self, $batch, $file, $last ) = @_;
464 36 ▶ return unless $batch && time - $$last >= $self->checkpoint_seconds;
Branch: 1 branch
BranchTrueFalseTotal
unless $batch and time - $$last >= $self->checkpoint_seconds 36 0 36
Condition33%1/3
$batch and time - $$last >= $self->checkpoint_seconds
!ll&&!rl&&r
0360
MC/DC0%0/2
$batch and time - $$last >= $self->checkpoint_seconds
$batch time - $$last >= $self->checkpoint_seconds
Truth table33%1/3
A and B
A= $batchB= time - $$last >= $self->checkpoint_seconds
ABresult
0X0
100
111
465 0 $$last = time;
466 0 ▶ return if eval { $batch->report->write($file); 1 };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $batch->report->write($file); 1 } } 0 0 0
467 0 ▶ print { $self->err } 'holmgang: checkpoint '.$file.' not written: '.$self->_text($@)."\n" unless $self->{_checkpoint_said}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{"_checkpoint_said"}++ 0 0 0
468 0 return;
469 }
470  
471 # an error text for a note: on one line, cut to 200 characters with an ellipsis.
472 # The result's error went through the target's scrub already (chat_turn_f).
473 10 ▶sub _one_line {
Subroutine _one_line: called CC=2 SCAR=6.9
474 10 my ( $self, $text ) = @_;
475 10 $text = join ' ', split ' ', $text;
476 10 ▶ return $text if length $text <= 200;
Branch: 1 branch
BranchTrueFalseTotal
if length $text <= 200 9 1 10
477 1 return substr( $text, 0, 200 ) =~ s/\s+\z//r." \x{2026}";
478 }
479  
480 # "2 error, 1 context_exceeded" in the order of the statuses
481 14 ▶sub _tally {
Subroutine _tally: called CC=2 SCAR=6.9
482 14 my ( $self, @statuses ) = @_;
483 14 my %n;
484 14 $n{$_}++ for @statuses;
485 14 return join ', ', map { $n{$_}.' '.$_ } grep { $n{$_} } qw( error context_exceeded no_vision );
486 }
487  
488  
489 #### report
490  
491 22 ▶sub cmd_report {
Subroutine cmd_report: called CC=16 SCAR=27.8
Pod documented
492 22 my ( $self, @argv ) = @_;
493 22 my ( $o, $bad ) = $self->_options( \@argv, 'by=s', 'format=s', 'suite=s@' );
494 22 ▶ return $self->_usage_error($bad) if $bad;
Branch: 1 branch
BranchTrueFalseTotal
if $bad 0 22 22
495 22 ▶ return $self->_usage_error('report needs at least one report file') unless @argv;
Branch: 1 branch
BranchTrueFalseTotal
unless @argv 1 21 22
496 21 ▶ my $by = $o->{by} // 'topic';
Condition100%2/2
$$o{"by"} // "topic"
l!l
219
MC/DC100%1/1
$$o{"by"} // "topic"
$$o{"by"}
Truth table100%2/2
A
A= $$o{"by"}
Aresult
11
00
497 21 ▶ return $self->_usage_error( '--by '.$by.': the evaluation is per topic, --by topic is the only one' )
Branch: 1 branch
BranchTrueFalseTotal
unless $by eq "topic" 1 20 21
498 unless $by eq 'topic';
499 20 ▶ my $format = $o->{format} // 'text';
Condition100%2/2
$$o{"format"} // "text"
l!l
515
MC/DC100%1/1
$$o{"format"} // "text"
$$o{"format"}
Truth table100%2/2
A
A= $$o{"format"}
Aresult
11
00
500 20 ▶ return $self->_usage_error( 'unknown --format '.$format.' (text, markdown, json)' )
Branch: 1 branch
BranchTrueFalseTotal
unless $format =~ /\A(?:text|markdown|json)\z/ 1 19 20
501 unless $format =~ /\A(?:text|markdown|json)\z/;
502 19 my @reports;
503 19 for my $file ( @argv ) {
504 23 my $r = eval { $self->report_class->read($file) };
505 23 ▶ return $self->_usage_error( 'report '.$file.' does not read: '.$self->_text($@) ) unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 7 16 23
506 16 push @reports, $r;
507 }
508 12 my ( $suites, $sbad ) = $self->_load_suites( $o->{suite} );
509 12 ▶ return $self->_usage_error($sbad) if $sbad;
Branch: 1 branch
BranchTrueFalseTotal
if $sbad 1 11 12
510 11 my $ev = eval { $self->evaluation_class->new( reports => \@reports, thresholds => $self->_thresholds($suites) ) };
511 11 ▶ return $self->_usage_error( 'reports do not evaluate: '.$self->_text($@) ) unless $ev;
Branch: 1 branch
BranchTrueFalseTotal
unless $ev 0 11 11
512 11 my $verdicts = eval { $ev->verdicts };
513 11 ▶ return $self->_usage_error( 'reports do not evaluate: '.$self->_text($@) ) unless $verdicts;
Branch: 1 branch
BranchTrueFalseTotal
unless $verdicts 1 10 11
514 10 ▶ my $text = $format eq 'json' ? Encode::decode( 'UTF-8', $ev->to_json )
Branch: 2 branches
BranchTrueFalseTotal
$format eq 'json' ? : 2 8 10
$format eq 'markdown' ? : 2 6 8
515 : $format eq 'markdown' ? $ev->to_markdown
516 : $ev->to_text;
517 10 ▶ $text .= "\n" unless $text =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\n\z/ 0 10 10
518 10 print { $self->out } $text;
519 10 ▶ return ( grep { !$_->{ok} } @$verdicts ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({not $$_{'ok'};} @$verdicts) ? : 5 5 10
520 }
521  
522  
523 16 __PACKAGE__->meta->make_immutable;
524  
525 16 1;
526  
527 __END__
« blib/lib/Langertha/Holmgang/Sim/Denken.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Sehen.pm »