Debian Codegraph @

lib/App/Yath/Command/replay.pm

raw
1 package App::Yath::Command::replay;
2 use strict;
3 use warnings;
4
5 our $VERSION = '1.000179';
6
7 use App::Yath::Options;
8 require App::Yath::Command::test;
9
10 use parent 'App::Yath::Command';
11 use Test2::Harness::Util::HashBase qw/+renderers <final_data <log_file <tests_seen <asserts_seen/;
12
13 include_options(
14 'App::Yath::Options::Debug',
15 'App::Yath::Options::Display',
16 'App::Yath::Options::PreCommand',
17 );
18
19
20 sub group { 'log' }
21
22 sub summary { "Replay a test run from an event log" }
23
24 sub cli_args { "[--] event_log.jsonl[.gz|.bz2] [job1, job2, ...]" }
25
26 sub description {
27 return <<" EOT";
28 This yath command will re-run the harness against an event log produced by a
29 previous test run. The only required argument is the path to the log file,
30 which maybe compressed. Any extra arguments are assumed to be job id's. If you
31 list any jobs, only listed jobs will be processed.
32
33 This command accepts all the same renderer/formatter options that the 'test'
34 command accepts.
35 EOT
36 }
37
38 sub init {
39 my $self = shift;
40 $self->SUPER::init() if $self->can('SUPER::init');
41
42 $self->{+TESTS_SEEN} //= 0;
43 $self->{+ASSERTS_SEEN} //= 0;
44 }
45
46 sub run {
47 my $self = shift;
48
49 my $args = $self->args;
50 my $settings = $self->settings;
51 my $renderers = $self->App::Yath::Command::test::renderers;
52
53 shift @$args if @$args && $args->[0] eq '--';
54
55 $self->{+LOG_FILE} = shift @$args or die "You must specify a log file";
56 die "'$self->{+LOG_FILE}' is not a valid log file" unless -f $self->{+LOG_FILE};
57 die "'$self->{+LOG_FILE}' does not look like a log file" unless $self->{+LOG_FILE} =~ m/\.jsonl(\.(gz|bz2))?$/;
58
59 my $jobs = @$args ? {map {$_ => 1} @$args} : undef;
60
61 my $stream = Test2::Harness::Util::File::JSONL->new(name => $self->{+LOG_FILE});
62
63 while (1) {
64 my @events = $stream->poll(max => 1000) or last;
65
66 for my $e (@events) {
67 last unless defined $e;
68
69 $self->{+TESTS_SEEN}++ if $e->{facet_data}->{harness_job_launch};
70 $self->{+ASSERTS_SEEN}++ if $e->{facet_data}->{assert};
71
72 if ($jobs) {
73 my $f = $e->{facet_data}->{harness_job_start} // $e->{facet_data}->{harness_job_queued};
74 if ($f && !$jobs->{$e->{job_id}}) {
75 for my $field (qw/rel_file abs_file file/) {
76 my $file = $f->{$field} or next;
77 next unless $jobs->{$file};
78 $jobs->{$e->{job_id}} = 1;
79 last;
80 }
81 }
82 }
83
84 if (my $final = $e->{facet_data}->{harness_final}) {
85 $self->{+FINAL_DATA} = $final;
86 }
87 else {
88 next if $jobs && !$jobs->{$e->{job_id}};
89 $_->render_event($e) for @$renderers;
90 }
91 }
92 }
93
94 $_->finish() for @$renderers;
95
96 my $final_data = $self->{+FINAL_DATA} or die "Log did not contain final data!\n";
97
98 $self->App::Yath::Command::test::render_final_data($final_data);
99 $self->App::Yath::Command::test::render_summary($final_data->{pass});
100
101 return $final_data->{pass} ? 0 : 1;
102 }
103
104 1;
105
106 __END__
107
108 =pod
109
110 =encoding UTF-8
111
112 =head1 NAME
113
114 App::Yath::Command::replay - Replay a test run from an event log
115
116 =head1 DESCRIPTION
117
118 This yath command will re-run the harness against an event log produced by a
119 previous test run. The only required argument is the path to the log file,
120 which maybe compressed. Any extra arguments are assumed to be job id's. If you
121 list any jobs, only listed jobs will be processed.
122
123 This command accepts all the same renderer/formatter options that the 'test'
124 command accepts.
125
126
127 =head1 USAGE
128
129 $ yath [YATH OPTIONS] replay [COMMAND OPTIONS]
130
131 =head2 YATH OPTIONS
132
133 =head3 Developer
134
135 =over 4
136
137 =item --dev-lib
138
139 =item --dev-lib=lib
140
141 =item -D
142
143 =item -D=lib
144
145 =item -Dlib
146
147 =item --no-dev-lib
148
149 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.
150
151 Can be specified multiple times
152
153
154 =back
155
156 =head3 Environment
157
158 =over 4
159
160 =item --persist-dir ARG
161
162 =item --persist-dir=ARG
163
164 =item --no-persist-dir
165
166 Where to find persistence files.
167
168
169 =item --persist-file ARG
170
171 =item --persist-file=ARG
172
173 =item --pfile ARG
174
175 =item --pfile=ARG
176
177 =item --no-persist-file
178
179 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.
180
181
182 =item --project ARG
183
184 =item --project=ARG
185
186 =item --project-name ARG
187
188 =item --project-name=ARG
189
190 =item --no-project
191
192 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.
193
194
195 =back
196
197 =head3 Help and Debugging
198
199 =over 4
200
201 =item --show-opts
202
203 =item --no-show-opts
204
205 Exit after showing what yath thinks your options mean
206
207
208 =item --version
209
210 =item -V
211
212 =item --no-version
213
214 Exit after showing a helpful usage message
215
216
217 =back
218
219 =head3 Plugins
220
221 =over 4
222
223 =item --no-scan-plugins
224
225 =item --no-no-scan-plugins
226
227 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.
228
229
230 =item --plugins PLUGIN
231
232 =item --plugins +App::Yath::Plugin::PLUGIN
233
234 =item --plugins PLUGIN=arg1,arg2,...
235
236 =item --plugin PLUGIN
237
238 =item --plugin +App::Yath::Plugin::PLUGIN
239
240 =item --plugin PLUGIN=arg1,arg2,...
241
242 =item -pPLUGIN
243
244 =item --no-plugins
245
246 Load a yath plugin.
247
248 Can be specified multiple times
249
250
251 =back
252
253 =head2 COMMAND OPTIONS
254
255 =head3 Cover Options
256
257 =over 4
258
259 =item --cover-aggregator ByTest
260
261 =item --cover-aggregator ByRun
262
263 =item --cover-aggregator +Custom::Aggregator
264
265 =item --cover-agg ByTest
266
267 =item --cover-agg ByRun
268
269 =item --cover-agg +Custom::Aggregator
270
271 =item --no-cover-aggregator
272
273 Choose a custom aggregator subclass
274
275
276 =item --cover-class ARG
277
278 =item --cover-class=ARG
279
280 =item --no-cover-class
281
282 Choose a Test2::Plugin::Cover subclass
283
284
285 =item --cover-dirs ARG
286
287 =item --cover-dirs=ARG
288
289 =item --cover-dir ARG
290
291 =item --cover-dir=ARG
292
293 =item --no-cover-dirs
294
295 NO DESCRIPTION - FIX ME
296
297 Can be specified multiple times
298
299
300 =item --cover-exclude-dirs ARG
301
302 =item --cover-exclude-dirs=ARG
303
304 =item --cover-exclude-dir ARG
305
306 =item --cover-exclude-dir=ARG
307
308 =item --no-cover-exclude-dirs
309
310 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.
311
312 Can be specified multiple times
313
314
315 =item --cover-exclude-private
316
317 =item --no-cover-exclude-private
318
319
320
321
322 =item --cover-files
323
324 =item --no-cover-files
325
326 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)
327
328
329 =item --cover-from path/to/log.jsonl
330
331 =item --cover-from http://example.com/coverage
332
333 =item --cover-from path/to/coverage.jsonl
334
335 =item --no-cover-from
336
337 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.
338
339
340 =item --cover-from-type json
341
342 =item --cover-from-type jsonl
343
344 =item --cover-from-type log
345
346 =item --no-cover-from-type
347
348 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.
349
350
351 =item --cover-manager My::Coverage::Manager
352
353 =item --no-cover-manager
354
355 Coverage 'from' manager to use when coverage data does not provide one
356
357
358 =item --cover-maybe-from path/to/log.jsonl
359
360 =item --cover-maybe-from http://example.com/coverage
361
362 =item --cover-maybe-from path/to/coverage.jsonl
363
364 =item --no-cover-maybe-from
365
366 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.
367
368
369 =item --cover-maybe-from-type json
370
371 =item --cover-maybe-from-type jsonl
372
373 =item --cover-maybe-from-type log
374
375 =item --no-cover-maybe-from-type
376
377 Same as "from_type" but for "maybe_from". Defaults to "from_type" if that is specified, otherwise auto-detect
378
379
380 =item --cover-metrics
381
382 =item --no-cover-metrics
383
384
385
386
387 =item --cover-types ARG
388
389 =item --cover-types=ARG
390
391 =item --cover-type ARG
392
393 =item --cover-type=ARG
394
395 =item --no-cover-types
396
397 NO DESCRIPTION - FIX ME
398
399 Can be specified multiple times
400
401
402 =item --cover-write
403
404 =item --cover-write=coverage.jsonl
405
406 =item --cover-write=coverage.json
407
408 =item --no-cover-write
409
410 Create a json or jsonl file of all coverage data seen during the run (This implies --cover-files).
411
412
413 =back
414
415 =head3 Display Options
416
417 =over 4
418
419 =item --color
420
421 =item --no-color
422
423 Turn color on, default is true if STDOUT is a TTY.
424
425
426 =item --hide-runner-output
427
428 =item --no-hide-runner-output
429
430 Hide output from the runner, showing only test output. (See Also truncate_runner_output)
431
432
433 =item --no-final-table
434
435 =item --no-no-final-table
436
437 When printing final results, don't use table-style display
438
439
440 =item --no-wrap
441
442 =item --no-no-wrap
443
444 Do not do fancy text-wrapping, let the terminal handle it
445
446
447 =item --progress
448
449 =item --no-progress
450
451 Toggle progress indicators. On by default if STDOUT is a TTY. You can use --no-progress to disable the 'events seen' counter and buffered event pre-display
452
453
454 =item --quiet
455
456 =item -q
457
458 =item --no-quiet
459
460 Be very quiet.
461
462 Can be specified multiple times
463
464
465 =item --renderers +My::Renderer
466
467 =item --renderers Renderer=arg1,arg2,...
468
469 =item --renderer +My::Renderer
470
471 =item --renderer Renderer=arg1,arg2,...
472
473 =item --no-renderers
474
475 Specify renderers, (Default: "Formatter=Test2"). Use "+" to give a fully qualified module name. Without "+" "Test2::Harness::Renderer::" will be prepended to your argument.
476
477 Can be specified multiple times. If the same key is listed multiple times the value lists will be appended together.
478
479
480 =item --show-times
481
482 =item -T
483
484 =item --no-show-times
485
486 Show the timing data for each job
487
488
489 =item --term-width 80
490
491 =item --term-width 200
492
493 =item --term-size 80
494
495 =item --term-size 200
496
497 =item --no-term-width
498
499 Alternative to setting $TABLE_TERM_SIZE. Setting this will override the terminal width detection to the number of characters specified.
500
501
502 =item --truncate-runner-output
503
504 =item --no-truncate-runner-output
505
506 Only show runner output that was generated after the current command. This is only useful with a persistent runner.
507
508
509 =item --verbose
510
511 =item -v
512
513 =item --no-verbose
514
515 Be more verbose
516
517 Can be specified multiple times
518
519
520 =back
521
522 =head3 Formatter Options
523
524 =over 4
525
526 =item --formatter ARG
527
528 =item --formatter=ARG
529
530 =item --no-formatter
531
532 NO DESCRIPTION - FIX ME
533
534
535 =item --qvf
536
537 =item --no-qvf
538
539 [Q]uiet, but [V]erbose on [F]ailure. Hide all output from tests when they pass, except to say they passed. If a test fails then ALL output from the test is verbosely output.
540
541
542 =item --show-job-end
543
544 =item --no-show-job-end
545
546 Show output when a job ends. (Default: on)
547
548
549 =item --show-job-info
550
551 =item --no-show-job-info
552
553 Show the job configuration when a job starts. (Default: off, unless -vv)
554
555
556 =item --show-job-launch
557
558 =item --no-show-job-launch
559
560 Show output for the start of a job. (Default: off unless -v)
561
562
563 =item --show-run-info
564
565 =item --no-show-run-info
566
567 Show the run configuration when a run starts. (Default: off, unless -vv)
568
569
570 =back
571
572 =head3 Git Options
573
574 =over 4
575
576 =item --git-change-base master
577
578 =item --git-change-base HEAD^
579
580 =item --git-change-base df22abe4
581
582 =item --no-git-change-base
583
584 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.
585
586
587 =back
588
589 =head3 Help and Debugging
590
591 =over 4
592
593 =item --dummy
594
595 =item -d
596
597 =item --no-dummy
598
599 Dummy run, do not actually execute anything
600
601 Can also be set with the following environment variables: C<T2_HARNESS_DUMMY>
602
603
604 =item --help
605
606 =item -h
607
608 =item --no-help
609
610 exit after showing help information
611
612
613 =item --interactive
614
615 =item -i
616
617 =item --no-interactive
618
619 Use interactive mode, 1 test at a time, stdin forwarded to it
620
621
622 =item --keep-dirs
623
624 =item --keep_dir
625
626 =item -k
627
628 =item --no-keep-dirs
629
630 Do not delete directories when done. This is useful if you want to inspect the directories used for various commands.
631
632
633 =item --procname-prefix ARG
634
635 =item --procname-prefix=ARG
636
637 =item --no-procname-prefix
638
639 Add a prefix to all proc names (as seen by ps).
640
641
642 =back
643
644 =head3 YathUI Options
645
646 =over 4
647
648 =item --yathui-api-key ARG
649
650 =item --yathui-api-key=ARG
651
652 =item --no-yathui-api-key
653
654 Yath-UI API key. This is not necessary if your Yath-UI instance is set to single-user
655
656
657 =item --yathui-grace
658
659 =item --no-yathui-grace
660
661 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.
662
663
664 =item --yathui-long-duration 10
665
666 =item --no-yathui-long-duration
667
668 Minimum duration length (seconds) before a test goes from MEDIUM to LONG
669
670
671 =item --yathui-medium-duration 5
672
673 =item --no-yathui-medium-duration
674
675 Minimum duration length (seconds) before a test goes from SHORT to MEDIUM
676
677
678 =item --yathui-mode summary
679
680 =item --yathui-mode qvf
681
682 =item --yathui-mode qvfd
683
684 =item --yathui-mode complete
685
686 =item --no-yathui-mode
687
688 Set the upload mode (default 'qvfd')
689
690
691 =item --yathui-project ARG
692
693 =item --yathui-project=ARG
694
695 =item --no-yathui-project
696
697 The Yath-UI project for your test results
698
699
700 =item --yathui-retry
701
702 =item --no-yathui-retry
703
704 How many times to try an operation before giving up
705
706 Can be specified multiple times
707
708
709 =item --yathui-url http://my-yath-ui.com/...
710
711 =item --uri http://my-yath-ui.com/...
712
713 =item --no-yathui-url
714
715 Yath-UI url
716
717
718 =back
719
720 =head1 SOURCE
721
722 The source code repository for Test2-Harness can be found at
723 F<http://github.com/Test-More/Test2-Harness/>.
724
725 =head1 MAINTAINERS
726
727 =over 4
728
729 =item Chad Granum E<lt>[email protected]<gt>
730
731 =back
732
733 =head1 AUTHORS
734
735 =over 4
736
737 =item Chad Granum E<lt>[email protected]<gt>
738
739 =back
740
741 =head1 COPYRIGHT
742
743 Copyright 2026 Chad Granum E<lt>[email protected]<gt>.
744
745 This program is free software; you can redistribute it and/or
746 modify it under the same terms as Perl itself.
747
748 See F<http://dev.perl.org/licenses/>
749
750 =cut
751