Skip to content

Commit

Permalink
fixme
Browse files Browse the repository at this point in the history
  • Loading branch information
exodist committed Jun 12, 2024
1 parent 3abae40 commit 06f417d
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 505 deletions.
460 changes: 9 additions & 451 deletions lib/App/Yath/Command/db.pm

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion lib/App/Yath/Command/server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ sub run {
my $server = $self->{+SERVER} = App::Yath::Server->new(schema_config => $config, $settings->webserver->all, qdb_params => $qdb_params);
$server->start_server;

my $user = $config->schema->resultset('User')->create({username => $ENV{USER}, password => 'password', realname => $ENV{USER}});
my $api_key = $config->schema->resultset('ApiKey')->create({value => gen_uuid, user_id => $user->user_id, name => "ephemeral"});
$ENV{YATH_API_KEY} = $api_key->value;

my $done = 0;
$SIG{TERM} = sub { $done++; print "Caught SIGTERM shutting down...\n" unless $daemon; $SIG{TERM} = 'DEFAULT' };
$SIG{INT} = sub { $done++; print "Caught SIGINT shutting down...\n" unless $daemon; $SIG{INT} = 'DEFAULT' };
Expand All @@ -110,6 +114,7 @@ sub run {
print "\nYath URL: $ENV{YATH_URL}\n\n";

if ($shell) {
local $ENV{YATH_SHELL} = 1;
system($ENV{SHELL});
}
else {
Expand Down Expand Up @@ -325,7 +330,7 @@ sub shell_db_text { "Open the database." }
sub shell_db { $_[0]->server->qdb->shell('harness_ui') }

sub shell_shell_text { "Open a shell" }
sub shell_shell { system($ENV{SHELL}) }
sub shell_shell { $ENV{YATH_SHELL} = 1; system($ENV{SHELL}) }

sub shell_load_text { "Load a database file (filename given as argument)" }
sub shell_load {
Expand Down
14 changes: 11 additions & 3 deletions lib/App/Yath/Options/Harness.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ option_group {group => 'harness', category => 'Harness Options'} => sub {
option tmpdir => (
type => 'Scalar',
alt => ['tmp-dir'],
description => 'Use a specific temp directory (Default: use system temp dir)',
from_env_vars => [qw/T2_HARNESS_TEMP_DIR YATH_TEMP_DIR TMPDIR TEMPDIR TMP_DIR TEMP_DIR/],
description => 'Use a specific temp directory (Default: create a temp dir under the system one)',
from_env_vars => [qw/T2_HARNESS_TEMP_DIR YATH_TEMP_DIR/],
clear_env_vars => [qw/T2_HARNESS_TEMP_DIR YATH_TEMP_DIR/],
default => sub { File::Spec->tmpdir },
set_env_vars => [qw/TMPDIR TEMPDIR TMP_DIR TEMP_DIR/],

default => sub {
my $tmpdir = File::Spec->tmpdir;
return $tmpdir if $tmpdir =~ m/yath/ && $ENV{YATH_SHELL};

my $dir = tempdir("yath-$ENV{USER}-$$-XXXXXX", CLEANUP => 1, TMPDIR => 1);
return $dir;
},
);

option clear => (
Expand Down
51 changes: 50 additions & 1 deletion lib/App/Yath/Options/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package App::Yath::Options::Server;
use strict;
use warnings;

our $VERSION = '2.000000';
use Getopt::Yath;

option_group {group => 'server', category => "Server Options"} => sub {
Expand All @@ -17,7 +18,7 @@ option_group {group => 'server', category => "Server Options"} => sub {
option shell => (
type => 'Bool',
default => 0,
description => "Drop into a shell where the server and database env vars are set so that yath commands will use the started server.",
description => "Drop into a shell where the server and/or database env vars are set so that yath commands will use the started server.",
);

option daemon => (
Expand Down Expand Up @@ -50,3 +51,51 @@ option_group {group => 'server', category => "Server Options"} => sub {
);
};

1;

__END__
=pod
=encoding UTF-8
=head1 NAME
App::Yath::Options::Server - FIXME
=head1 DESCRIPTION
=head1 PROVIDED OPTIONS POD IS AUTO-GENERATED
=head1 SOURCE
The source code repository for Test2-Harness can be found at
L<http://github.com/Test-More/Test2-Harness/>.
=head1 MAINTAINERS
=over 4
=item Chad Granum E<lt>exodist@cpan.orgE<gt>
=back
=head1 AUTHORS
=over 4
=item Chad Granum E<lt>exodist@cpan.orgE<gt>
=back
=head1 COPYRIGHT
Copyright Chad Granum E<lt>exodist7@gmail.comE<gt>.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
See L<http://dev.perl.org/licenses/>
=cut
2 changes: 1 addition & 1 deletion lib/App/Yath/Plugin/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use parent 'App::Yath::Plugin';

include_options(
'App::Yath::Options::DB',
'App::Yath::Options::Upload',
'App::Yath::Options::Publish',
'App::Yath::Options::Yath',
);

Expand Down
1 change: 1 addition & 0 deletions lib/App/Yath/Plugin/SysInfo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sub run_fields {
user => $ENV{USER},
shell => $ENV{SHELL},
term => $ENV{TERM},
(map { m/(YATH|T2|TEST2|HARNESS|PERL|CPAN|TAP)/i ? ($_ => $ENV{$_}) : ()} grep keys %ENV),
},

ipc => {
Expand Down
8 changes: 4 additions & 4 deletions lib/App/Yath/Renderer/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use Time::HiRes qw/time/;

use Test2::Harness::Util qw/clean_path/;
use Test2::Harness::IPC::Util qw/start_process/;
use Test2::Harness::Util::JSON qw/encode_ascii_json/;
use Test2::Harness::Util::JSON qw/encode_ascii_json_file encode_ascii_json/;
use Test2::Util::UUID qw/gen_uuid/;

use parent 'App::Yath::Renderer';
Expand Down Expand Up @@ -49,16 +49,16 @@ sub start {
[
$^X, # perl
(map { ("-I$_") } grep { -d $_ && !$seen{$_}++ } @INC), # Use the dev libs specified
"-mApp::Yath::Schema::RunProcessor", # Load processor
"-mApp::Yath::Schema::RunProcessor", # Load processor
"-mGetopt::Yath::Settings", # Load settings lib
'-e' => <<" EOT", # Run it.
exit(
App::Yath::Schema::RunProcessor->process_stdin(
Getopt::Yath::Settings->FROM_JSON(\$ARGV[0])
Getopt::Yath::Settings->FROM_JSON_FILE(\$ARGV[0], unlink => 1)
)
);
EOT
encode_ascii_json($self->{+SETTINGS}), # Pass settings in as arg
encode_ascii_json_file($self->{+SETTINGS}), # Pass settings in as arg
],
sub {
close(STDIN);
Expand Down
1 change: 0 additions & 1 deletion lib/App/Yath/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use utf8;
use strict;
use warnings;
use Carp qw/confess/;
use Carp::Always;

our $VERSION = '2.000000';

Expand Down
8 changes: 3 additions & 5 deletions lib/App/Yath/Schema/RunProcessor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ sub init {
$self->{+BUFFER_SIZE} //= 100;
}

sub process_log_file {
my $class = shift;
}

sub process_stdin {
my $class = shift;
my ($settings) = @_;
Expand All @@ -140,8 +136,10 @@ sub process_handle {

my $cb = $class->process_lines($settings);

while (my $line = <$fh>) {
while (1) {
my $line = <$fh>;
$cb->($line);
last unless $line;
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/App/Yath/Server/Controller/Upload.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ sub handle {

my $res = resp(200);

my $run_id = $self->process_form($res) if $req->parameters->{action};
my $run_uuid = $self->process_form($res) if $req->parameters->{action};

my $tx = Text::Xslate->new(path => [share_dir('templates')]);
my $user = $req->user;

if ($req->parameters->{json}) {
$res->as_json($run_id ? (run_id => $run_id) : ());
$res->as_json($run_uuid ? (run_uuid => $run_uuid) : ());
return $res;
}

Expand Down Expand Up @@ -82,20 +82,20 @@ sub process_form {
unless $file =~ m/\.jsonl\.(bz2|gz)$/i;
my $ext = lc($1);

my ($run_id);
my ($run_uuid);
my $ok = eval {
my $fh = open_file($tmp, '<', ext => $ext);
my $header = <$fh>;
close($fh);

$run_id = decode_json($header)->{facet_data}->{harness_run}->{run_id};
$run_uuid = decode_json($header)->{facet_data}->{harness_run}->{run_id};
};
return $res->add_error("Error decoding json: $@") unless $ok;

open(my $fh, '<:raw', $tmp) or die "Could not open uploaded file '$tmp': $!";

my $run = $self->schema->resultset('Run')->create({
$run_id ? (run_uuid => $run_id) : (),
$run_uuid ? (run_uuid => $run_uuid) : (),
user_id => ref($user) ? $user->user_id : 1,
project_id => $project->project_id,
mode => $mode,
Expand All @@ -109,7 +109,7 @@ sub process_form {
});

$res->add_message("Upload Success, added import to queue");
return $run->run_id;
return $run->run_uuid;
}

sub api_user {
Expand Down
6 changes: 4 additions & 2 deletions lib/Getopt/Yath.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ sub import {
};

$export{include_options} = sub {
for my $module (@_) {
while (my $module = shift @_) {
my $file = mod2file($module);
require $file unless $INC{$file};

croak "Module '$module' does not have an 'options' method"
unless $module->can('options');

$instance->include($module->options);
my $list = @_ && ref($_[0]) eq 'ARRAY' ? shift(@_) : undef;

$instance->include($module->options, $list);
}
};

Expand Down
10 changes: 8 additions & 2 deletions lib/Getopt/Yath/Instance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sub _post {

sub include {
my $self = shift;
my ($other) = @_;
my ($other, $list) = @_;

return unless $other;
return if $self->{+DEDUP}->{$other}++;
Expand All @@ -76,7 +76,13 @@ sub include {
}
}

$self->_option($_) for @{$other->options};
if ($list) {
my %want = map {$_ => 1} @$list;
$self->_option($_) for grep { $want{$_->title} || $want{$_->field} || $want{$_->name} } @{$other->options};
}
else {
$self->_option($_) for @{$other->options};
}

for my $set (values %{$other->posts}) {
for my $post (@$set) {
Expand Down
10 changes: 9 additions & 1 deletion lib/Getopt/Yath/Settings.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Carp();

use Getopt::Yath::Settings::Group;

use Test2::Harness::Util::JSON qw/decode_json/;
use Test2::Harness::Util::JSON qw/decode_json decode_json_file/;

sub new {
my $class = shift;
Expand Down Expand Up @@ -76,6 +76,14 @@ sub AUTOLOAD {
$this->group($group);
}

sub FROM_JSON_FILE {
my $class = shift;
my ($file, %params) = @_;

my $data = decode_json_file($file, %params);
$class->new($data);
}

sub FROM_JSON {
my $class = shift;
my ($json) = @_;
Expand Down
17 changes: 15 additions & 2 deletions lib/Test2/Harness/Collector.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use Test2::Harness::Collector::Auditor::Job;
use Test2::Harness::Collector::IOParser::Stream;

use Test2::Harness::Util qw/mod2file parse_exit open_file chmod_tmp/;
use Test2::Harness::Util::JSON qw/decode_json encode_ascii_json/;
use Test2::Harness::Util::JSON qw/decode_json encode_ascii_json decode_json_file/;
use Test2::Harness::IPC::Util qw/pid_is_running swap_io start_process ipc_connect ipc_loop inflate set_procname/;

BEGIN {
Expand Down Expand Up @@ -116,7 +116,20 @@ sub init {
my $warned = 0;
sub collect {
my $class = shift;
my %params = (@_ == 1) ? (%{decode_json($_[0])}) : (@_);
my %params;

if (@_ == 1) {
my ($in) = @_;
if ($in =~ m/\.json$/ || -f $in) {
%params = %{decode_json_file($in, unlink => 1)};
}
else {
%params = %{decode_json($in)};
}
}
else {
%params = @_;
}

die "No root pid" unless $params{root_pid};
$class->setsid if $params{setsid};
Expand Down
4 changes: 2 additions & 2 deletions lib/Test2/Harness/IPC/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use Data::Dumper qw/Dumper/;
use POSIX();
use IO::Select();

use Test2::Harness::Util::JSON qw/encode_pretty_json encode_json/;
use Test2::Harness::Util::JSON qw/encode_pretty_json encode_json encode_ascii_json_file/;
use Test2::Harness::Util qw/mod2file/;

use Importer Importer => 'import';
Expand Down Expand Up @@ -132,7 +132,7 @@ sub start_collected_process {
(map { ("-I$_") } grep { -d $_ && !$seen{$_}++ } @INC), # Use the dev libs specified
'-mTest2::Harness::Collector', # Load Collector
'-e' => 'exit(Test2::Harness::Collector->collect($ARGV[0]))', # Run it.
encode_json(\%params), # json data for what to do
encode_ascii_json_file(\%params), # json data for what to do
],
$post_fork,
);
Expand Down
Loading

0 comments on commit 06f417d

Please sign in to comment.