From f26b3e177947619987bd9e2671340c733b524e45 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 29 Nov 2021 12:19:04 -0800 Subject: [PATCH 1/7] Hydra/Event: fix scalar context warning 12:10:15 hydra-notify.1 | %channels_to_events{...} in scalar context better written as $channels_to_events{...} at /home/vin/workspace/vcs/hydra/src/lib/Hydra/Event.pm line 20. --- src/lib/Hydra/Event.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Hydra/Event.pm b/src/lib/Hydra/Event.pm index e3954308..b14d74f4 100644 --- a/src/lib/Hydra/Event.pm +++ b/src/lib/Hydra/Event.pm @@ -17,7 +17,7 @@ sub parse_payload :prototype($$) { my ($channel_name, $payload) = @_; my @payload = split /\t/, $payload; - my $parser = %channels_to_events{$channel_name}; + my $parser = $channels_to_events{$channel_name}; unless (defined $parser) { die "Invalid channel name: '$channel_name'"; } From 78233b80839a69572f870ce6a56c3b1417c48475 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 30 Nov 2021 12:26:54 -0800 Subject: [PATCH 2/7] Hydra: Unicode::Encoding is auto-applied 11:28:20 hydra-server.1 | [warn] Unicode::Encoding plugin is auto-applied, please remove this from your appclass and make sure to define "encoding" config --- src/lib/Hydra.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/Hydra.pm b/src/lib/Hydra.pm index 6d85f3a9..07aec922 100644 --- a/src/lib/Hydra.pm +++ b/src/lib/Hydra.pm @@ -8,7 +8,6 @@ use Hydra::Plugin; use Hydra::Model::DB; use Catalyst::Runtime '5.70'; use Catalyst qw/ConfigLoader - Unicode::Encoding Static::Simple StackTrace Authentication From d56815cae636d0e245922badb9e6cb8871abc715 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 30 Nov 2021 12:33:04 -0800 Subject: [PATCH 3/7] Hydra/Helper/CatalystUtils: default trim arg to empty string 12:34:12 hydra-server.1 | Use of uninitialized value $s in substitution (s///) at /home/vin/workspace/vcs/hydra/src/script/../lib/Hydra/Helper/CatalystUtils.pm line 283, <$fh> line 1. --- src/lib/Hydra/Helper/CatalystUtils.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index 0b48e455..64e3c44f 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -279,7 +279,7 @@ sub requirePost { sub trim { - my $s = shift; + my $s = shift // ""; $s =~ s/^\s+|\s+$//g; return $s; } From 085b02e092b5984ad7d1501830933d349a293cc1 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 1 Dec 2021 08:38:43 -0800 Subject: [PATCH 4/7] t/Helper/CatalystUtils.t: test trim functionality --- t/Helper/CatalystUtils.t | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 t/Helper/CatalystUtils.t diff --git a/t/Helper/CatalystUtils.t b/t/Helper/CatalystUtils.t new file mode 100644 index 00000000..26f8dcde --- /dev/null +++ b/t/Helper/CatalystUtils.t @@ -0,0 +1,28 @@ +use strict; +use warnings; +use Setup; +use Test2::V0; +use Hydra::Helper::CatalystUtils; + +subtest "trim" => sub { + my %values = ( + "" => "", + "šŸŒ®" => 'šŸŒ®', + " šŸŒ®" => 'šŸŒ®', + "šŸŒ® " => 'šŸŒ®', + " šŸŒ® " => 'šŸŒ®', + "\nšŸŒ® " => 'šŸŒ®', + "\n\tšŸŒ®\n\n\t" => 'šŸŒ®', + ); + + for my $input (keys %values) { + my $value = $values{$input}; + is(trim($input), $value, "Trim the value: " . $input); + } + + my $uninitialized; + + is(trim($uninitialized), '', "Trimming an uninitialized value"); +}; + +done_testing; From ecb1454cf1b892ddd2c4fd55c9023fafa25ba152 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Fri, 3 Dec 2021 11:33:11 -0800 Subject: [PATCH 5/7] t/Controller/Root: test narinfo path --- t/Controller/Root/narinfo.t | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 t/Controller/Root/narinfo.t diff --git a/t/Controller/Root/narinfo.t b/t/Controller/Root/narinfo.t new file mode 100644 index 00000000..297d336b --- /dev/null +++ b/t/Controller/Root/narinfo.t @@ -0,0 +1,48 @@ +use strict; +use warnings; +use Setup; +use Data::Dumper; +use JSON qw(decode_json); +my %ctx = test_init( + # Without this, the test will fail because a `file:` store is not treated as a + # local store by `isLocalStore` in src/lib/Hydra/Helper/Nix.pm, and any + # requests to /HASH.narinfo will fail. + use_external_destination_store => 0 +); + +require Hydra::Schema; +require Hydra::Model::DB; +require Hydra::Helper::Nix; + +use Test2::V0; +require Catalyst::Test; +use HTTP::Request::Common; +Catalyst::Test->import('Hydra'); + +my $db = Hydra::Model::DB->new; +hydra_setup($db); + +my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"}); + +my $jobset = createBaseJobset("basic", "basic.nix", $ctx{jobsdir}); + +ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0"); +for my $build (queuedBuildsForJobset($jobset)) { + ok(runBuild($build), "Build '".$build->job."' from jobs/basic.nix should exit with return code 0"); +} + +subtest "/HASH.narinfo" => sub { + my $build_redirect = request(GET '/job/tests/basic/empty_dir/latest-finished'); + my $url = URI->new($build_redirect->header('location'))->path; + my $json = request(GET $url, Accept => 'application/json'); + my $data = decode_json($json->content); + my $outpath = $data->{buildoutputs}{out}{path}; + my ($hash) = $outpath =~ qr{/nix/store/([a-z0-9]{32}).*}; + my $narinfo_response = request(GET "/$hash.narinfo"); + ok($narinfo_response->is_success, "Getting the narinfo of a build"); + + my ($storepath) = $narinfo_response->content =~ qr{StorePath: (.*)}; + is($storepath, $outpath, "The returned store path is the same as the out path") +}; + +done_testing; From 5659d2982c310cd87b21daeda87a4ec8be796358 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 30 Nov 2021 12:37:17 -0800 Subject: [PATCH 6/7] Hydra/Controller/Root: remove deprecated LocalRegex 11:38:20 hydra-server.1 | DEPRECATION WARNING: The Regex dispatch type is deprecated. 11:38:20 hydra-server.1 | It is recommended that you convert Regex and LocalRegex 11:38:20 hydra-server.1 | methods to Chained methods. at /nix/store/aa6gw57fnahd4824pbhmvcs0jlypmynq-hydra-perl-deps/lib/perl5/site_perl/5.32.1/Catalyst/DispatchType/Regex.pm line 210. --- flake.nix | 1 - src/lib/Hydra/Controller/Root.pm | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index b93ad4aa..5d76568a 100644 --- a/flake.nix +++ b/flake.nix @@ -429,7 +429,6 @@ CatalystAuthenticationStoreDBIxClass CatalystAuthenticationStoreLDAP CatalystDevel - CatalystDispatchTypeRegex CatalystPluginAccessLog CatalystPluginAuthorizationRoles CatalystPluginCaptcha diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index df178df4..01bb7b44 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -15,6 +15,9 @@ use JSON; use List::Util qw[min max]; use List::MoreUtils qw{any}; use Net::Prometheus; +use Types::Standard qw/StrMatch/; + +use constant NARINFO_REGEX => qr{^([a-z0-9]{32})\.narinfo$}; # Put this controller at top-level. __PACKAGE__->config->{namespace} = ''; @@ -349,17 +352,17 @@ sub nix_cache_info :Path('nix-cache-info') :Args(0) { } -sub narinfo :LocalRegex('^([a-z0-9]+).narinfo$') :Args(0) { - my ($self, $c) = @_; +sub narinfo :Path :Args(StrMatch[NARINFO_REGEX]) { + my ($self, $c, $narinfo) = @_; if (!isLocalStore) { notFound($c, "There is no binary cache here."); } else { - my $hash = $c->req->captures->[0]; + my ($hash) = $narinfo =~ NARINFO_REGEX; - die if length($hash) != 32; + die("Hash length was not 32") if length($hash) != 32; my $path = queryPathFromHashPart($hash); if (!$path) { From 47cabac4bf3a09c248affa15b483bd89b4655a57 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 30 Nov 2021 12:37:55 -0800 Subject: [PATCH 7/7] hydra-eval-jobset: fix use of uninitialized value This happens with flake jobsets for obvious reasons (namely, that nixexprinput and nixexprpath may be undefined for a flake jobset). 12:38:59 hydra-evaluator.1 | Use of uninitialized value $args[0] in join or string at /home/vin/workspace/vcs/hydra/src/script/hydra-eval-jobset line 648. 12:38:59 hydra-evaluator.1 | Use of uninitialized value $args[1] in join or string at /home/vin/workspace/vcs/hydra/src/script/hydra-eval-jobset line 648. --- src/script/hydra-eval-jobset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/hydra-eval-jobset b/src/script/hydra-eval-jobset index 7a9af09f..ad757771 100755 --- a/src/script/hydra-eval-jobset +++ b/src/script/hydra-eval-jobset @@ -644,7 +644,7 @@ sub checkJobsetWrapped { # Hash the arguments to hydra-eval-jobs and check the # JobsetInputHashes to see if the previous evaluation had the same # inputs. If so, bail out. - my @args = ($jobset->nixexprinput, $jobset->nixexprpath, inputsToArgs($inputInfo)); + my @args = ($jobset->nixexprinput // "", $jobset->nixexprpath // "", inputsToArgs($inputInfo)); my $argsHash = sha256_hex("@args"); my $prevEval = getPrevJobsetEval($db, $jobset, 0); if (defined $prevEval && $prevEval->hash eq $argsHash && !$dryRun && !$jobset->forceeval && $prevEval->flake eq $flakeRef) {