Debian Codegraph @

lib/App/Yath/Command/collector.pm

raw
1 package App::Yath::Command::collector;
2 use strict;
3 use warnings;
4
5 our $VERSION = '1.000179';
6
7 use File::Spec;
8
9 use App::Yath::Util qw/isolate_stdout/;
10
11 use Test2::Harness::Util::JSON qw/decode_json/;
12 use Test2::Harness::Util qw/mod2file/;
13
14 use Test2::Harness::Run;
15 use Test2::Harness::Stall::Detector();
16 use Test2::Harness::Stall::Trace qw/install_trace_handler/;
17
18 use parent 'App::Yath::Command';
19 use Test2::Harness::Util::HashBase;
20
21 sub internal_only { 1 }
22 sub summary { "For internal use only" }
23 sub name { 'collector' }
24
25 sub run {
26 my $self = shift;
27 my ($collector_class, $dir, $run_id, $runner_pid, %args) = @{$self->{+ARGS}};
28
29 my $name = 'yath-collector';
30 $name = "$args{procname_prefix}-${name}" if $args{procname_prefix};
31 $0 = $name;
32
33 my $fh = isolate_stdout();
34
35 my $settings = Test2::Harness::Settings->new(File::Spec->catfile($dir, 'settings.json'));
36
37 # List context on purpose: parse_spec returns a list, so a boolean test
38 # would see only its last value and miss STRONG:0.
39 my %stall =
40 $settings->check_prefix('runner')
41 ? Test2::Harness::Stall::Detector->parse_spec($settings->runner->stall_report)
42 : ();
43 install_trace_handler(File::Spec->catdir($dir, 'stall')) if %stall;
44
45 require(mod2file($collector_class));
46
47 my $run = Test2::Harness::Run->new(%{decode_json(<STDIN>)});
48
49 my $collector = $collector_class->new(
50 %args,
51 settings => $settings,
52 workdir => $dir,
53 run_id => $run_id,
54 runner_pid => $runner_pid,
55 run => $run,
56 # as_json may already have the json form of the event cached, if so
57 # we can avoid doing an extra call to encode_json
58 action => sub { print $fh defined($_[0]) ? $_[0]->as_json . "\n" : "null\n"; },
59 );
60
61 local $SIG{PIPE} = 'IGNORE';
62 my $ok = eval { $collector->process(); 1 };
63 my $err = $@;
64
65 eval { print $fh "null\n"; 1 } or warn $@;
66
67 die $err unless $ok;
68
69 return 0;
70 }
71
72 1;
73
74 __END__
75
76 =pod
77
78 =encoding UTF-8
79
80 =head1 NAME
81
82 App::Yath::Command::collector - For internal use only
83
84 =head1 DESCRIPTION
85
86 No Description
87
88 =head1 USAGE
89
90 $ yath [YATH OPTIONS] collector [COMMAND OPTIONS]
91
92 =head2 YATH OPTIONS
93
94 =head3 Developer
95
96 =over 4
97
98 =item --dev-lib
99
100 =item --dev-lib=lib
101
102 =item -D
103
104 =item -D=lib
105
106 =item -Dlib
107
108 =item --no-dev-lib
109
110 Add paths to @INC before loading ANYTHING. This is what you use if you are developing yath or yath plugins to make sure the yath script finds the local code instead of the installed versions of the same code. You can provide an argument (-Dfoo) to provide a custom path, or you can just use -D without and arg to add lib, blib/lib and blib/arch.
111
112 Can be specified multiple times
113
114
115 =back
116
117 =head3 Environment
118
119 =over 4
120
121 =item --persist-dir ARG
122
123 =item --persist-dir=ARG
124
125 =item --no-persist-dir
126
127 Where to find persistence files.
128
129
130 =item --persist-file ARG
131
132 =item --persist-file=ARG
133
134 =item --pfile ARG
135
136 =item --pfile=ARG
137
138 =item --no-persist-file
139
140 Where to find the persistence file. The default is /{system-tempdir}/project-yath-persist.json. If no project is specified then it will fall back to the current directory. If the current directory is not writable it will default to /tmp/yath-persist.json which limits you to one persistent runner on your system.
141
142
143 =item --project ARG
144
145 =item --project=ARG
146
147 =item --project-name ARG
148
149 =item --project-name=ARG
150
151 =item --no-project
152
153 This lets you provide a label for your current project/codebase. This is best used in a .yath.rc file. This is necessary for a persistent runner.
154
155
156 =back
157
158 =head3 Help and Debugging
159
160 =over 4
161
162 =item --show-opts
163
164 =item --no-show-opts
165
166 Exit after showing what yath thinks your options mean
167
168
169 =item --version
170
171 =item -V
172
173 =item --no-version
174
175 Exit after showing a helpful usage message
176
177
178 =back
179
180 =head3 Plugins
181
182 =over 4
183
184 =item --no-scan-plugins
185
186 =item --no-no-scan-plugins
187
188 Normally yath scans for and loads all App::Yath::Plugin::* modules in order to bring in command-line options they may provide. This flag will disable that. This is useful if you have a naughty plugin that is loading other modules when it should not.
189
190
191 =item --plugins PLUGIN
192
193 =item --plugins +App::Yath::Plugin::PLUGIN
194
195 =item --plugins PLUGIN=arg1,arg2,...
196
197 =item --plugin PLUGIN
198
199 =item --plugin +App::Yath::Plugin::PLUGIN
200
201 =item --plugin PLUGIN=arg1,arg2,...
202
203 =item -pPLUGIN
204
205 =item --no-plugins
206
207 Load a yath plugin.
208
209 Can be specified multiple times
210
211
212 =back
213
214 =head2 COMMAND OPTIONS
215
216 =head3 Cover Options
217
218 =over 4
219
220 =item --cover-aggregator ByTest
221
222 =item --cover-aggregator ByRun
223
224 =item --cover-aggregator +Custom::Aggregator
225
226 =item --cover-agg ByTest
227
228 =item --cover-agg ByRun
229
230 =item --cover-agg +Custom::Aggregator
231
232 =item --no-cover-aggregator
233
234 Choose a custom aggregator subclass
235
236
237 =item --cover-class ARG
238
239 =item --cover-class=ARG
240
241 =item --no-cover-class
242
243 Choose a Test2::Plugin::Cover subclass
244
245
246 =item --cover-dirs ARG
247
248 =item --cover-dirs=ARG
249
250 =item --cover-dir ARG
251
252 =item --cover-dir=ARG
253
254 =item --no-cover-dirs
255
256 NO DESCRIPTION - FIX ME
257
258 Can be specified multiple times
259
260
261 =item --cover-exclude-dirs ARG
262
263 =item --cover-exclude-dirs=ARG
264
265 =item --cover-exclude-dir ARG
266
267 =item --cover-exclude-dir=ARG
268
269 =item --no-cover-exclude-dirs
270
271 Directory to leave out of file coverage and coverage metrics, along with everything under it at any depth. May be specified multiple times. Wildcards are expanded when the option is parsed, so a pattern matching nothing excludes nothing. Values are word-split first, so a path containing whitespace must be quoted or backslash-escaped. A resolved path may not contain a comma.
272
273 Can be specified multiple times
274
275
276 =item --cover-exclude-private
277
278 =item --no-cover-exclude-private
279
280
281
282
283 =item --cover-files
284
285 =item --no-cover-files
286
287 Use Test2::Plugin::Cover to collect coverage data for what files are touched by what tests. Unlike Devel::Cover this has very little performance impact (About 4% difference)
288
289
290 =item --cover-from path/to/log.jsonl
291
292 =item --cover-from http://example.com/coverage
293
294 =item --cover-from path/to/coverage.jsonl
295
296 =item --no-cover-from
297
298 This can be a test log, a coverage dump (old style json or new jsonl format), or a url to any of the previous. Tests will not be run if the file/url is invalid.
299
300
301 =item --cover-from-type json
302
303 =item --cover-from-type jsonl
304
305 =item --cover-from-type log
306
307 =item --no-cover-from-type
308
309 File type for coverage source. Usually it can be detected, but when it cannot be you should specify. "json" is old style single-blob coverage data, "jsonl" is the new by-test style, "log" is a logfile from a previous run.
310
311
312 =item --cover-manager My::Coverage::Manager
313
314 =item --no-cover-manager
315
316 Coverage 'from' manager to use when coverage data does not provide one
317
318
319 =item --cover-maybe-from path/to/log.jsonl
320
321 =item --cover-maybe-from http://example.com/coverage
322
323 =item --cover-maybe-from path/to/coverage.jsonl
324
325 =item --no-cover-maybe-from
326
327 This can be a test log, a coverage dump (old style json or new jsonl format), or a url to any of the previous. Tests will continue even if the coverage file/url is invalid.
328
329
330 =item --cover-maybe-from-type json
331
332 =item --cover-maybe-from-type jsonl
333
334 =item --cover-maybe-from-type log
335
336 =item --no-cover-maybe-from-type
337
338 Same as "from_type" but for "maybe_from". Defaults to "from_type" if that is specified, otherwise auto-detect
339
340
341 =item --cover-metrics
342
343 =item --no-cover-metrics
344
345
346
347
348 =item --cover-types ARG
349
350 =item --cover-types=ARG
351
352 =item --cover-type ARG
353
354 =item --cover-type=ARG
355
356 =item --no-cover-types
357
358 NO DESCRIPTION - FIX ME
359
360 Can be specified multiple times
361
362
363 =item --cover-write
364
365 =item --cover-write=coverage.jsonl
366
367 =item --cover-write=coverage.json
368
369 =item --no-cover-write
370
371 Create a json or jsonl file of all coverage data seen during the run (This implies --cover-files).
372
373
374 =back
375
376 =head3 Git Options
377
378 =over 4
379
380 =item --git-change-base master
381
382 =item --git-change-base HEAD^
383
384 =item --git-change-base df22abe4
385
386 =item --no-git-change-base
387
388 Find files changed by all commits in the current branch from most recent stopping when a commit is found that is also present in the history of the branch/commit specified as the change base.
389
390
391 =back
392
393 =head3 Help and Debugging
394
395 =over 4
396
397 =item --dummy
398
399 =item -d
400
401 =item --no-dummy
402
403 Dummy run, do not actually execute anything
404
405 Can also be set with the following environment variables: C<T2_HARNESS_DUMMY>
406
407
408 =item --help
409
410 =item -h
411
412 =item --no-help
413
414 exit after showing help information
415
416
417 =item --interactive
418
419 =item -i
420
421 =item --no-interactive
422
423 Use interactive mode, 1 test at a time, stdin forwarded to it
424
425
426 =item --keep-dirs
427
428 =item --keep_dir
429
430 =item -k
431
432 =item --no-keep-dirs
433
434 Do not delete directories when done. This is useful if you want to inspect the directories used for various commands.
435
436
437 =item --procname-prefix ARG
438
439 =item --procname-prefix=ARG
440
441 =item --no-procname-prefix
442
443 Add a prefix to all proc names (as seen by ps).
444
445
446 =back
447
448 =head3 YathUI Options
449
450 =over 4
451
452 =item --yathui-api-key ARG
453
454 =item --yathui-api-key=ARG
455
456 =item --no-yathui-api-key
457
458 Yath-UI API key. This is not necessary if your Yath-UI instance is set to single-user
459
460
461 =item --yathui-grace
462
463 =item --no-yathui-grace
464
465 If yath cannot connect to yath-ui it normally throws an error, use this to make it fail gracefully. You get a warning, but things keep going.
466
467
468 =item --yathui-long-duration 10
469
470 =item --no-yathui-long-duration
471
472 Minimum duration length (seconds) before a test goes from MEDIUM to LONG
473
474
475 =item --yathui-medium-duration 5
476
477 =item --no-yathui-medium-duration
478
479 Minimum duration length (seconds) before a test goes from SHORT to MEDIUM
480
481
482 =item --yathui-mode summary
483
484 =item --yathui-mode qvf
485
486 =item --yathui-mode qvfd
487
488 =item --yathui-mode complete
489
490 =item --no-yathui-mode
491
492 Set the upload mode (default 'qvfd')
493
494
495 =item --yathui-project ARG
496
497 =item --yathui-project=ARG
498
499 =item --no-yathui-project
500
501 The Yath-UI project for your test results
502
503
504 =item --yathui-retry
505
506 =item --no-yathui-retry
507
508 How many times to try an operation before giving up
509
510 Can be specified multiple times
511
512
513 =item --yathui-url http://my-yath-ui.com/...
514
515 =item --uri http://my-yath-ui.com/...
516
517 =item --no-yathui-url
518
519 Yath-UI url
520
521
522 =back
523
524 =head1 SOURCE
525
526 The source code repository for Test2-Harness can be found at
527 F<http://github.com/Test-More/Test2-Harness/>.
528
529 =head1 MAINTAINERS
530
531 =over 4
532
533 =item Chad Granum E<lt>[email protected]<gt>
534
535 =back
536
537 =head1 AUTHORS
538
539 =over 4
540
541 =item Chad Granum E<lt>[email protected]<gt>
542
543 =back
544
545 =head1 COPYRIGHT
546
547 Copyright 2026 Chad Granum E<lt>[email protected]<gt>.
548
549 This program is free software; you can redistribute it and/or
550 modify it under the same terms as Perl itself.
551
552 See F<http://dev.perl.org/licenses/>
553
554 =cut
555