From 14ce518e7f5cb70a10a904a05ece7d88d31b1a7e Mon Sep 17 00:00:00 2001 From: Marius Kittler Date: Thu, 29 Feb 2024 18:04:13 +0100 Subject: [PATCH 1/2] Ensure npm packages are installed when invoking tests Tested by removing the `node_modules` directory and invoking commands like `make test TESTS=t/api/01-workers.t` locally. `npm install` is only called if `package-lock.json` has been modified since the last call. Related ticket: https://progress.opensuse.org/issues/155713 --- Makefile | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 28bd0356d62..696481b1466 100644 --- a/Makefile +++ b/Makefile @@ -159,6 +159,12 @@ else install: install-opensuse endif +# Ensure npm packages are installed and up-to-date (unless local-npm-registry is installed; in this case we can +# assume installing npm packages is taken care of separately, e.g. in builds on OBS) +node_modules: package-lock.json + @which local-npm-registry >/dev/null 2>&1 || npm install --no-audit --no-fund + @touch node_modules + .PHONY: test ifeq ($(TRAVIS),true) test: run-tests-within-container @@ -185,44 +191,44 @@ endif test-checkstyle: test-checkstyle-standalone test-tidy-compile .PHONY: test-t -test-t: +test-t: node_modules $(MAKE) test-with-database TIMEOUT_M=25 PROVE_ARGS="$$HARNESS t/*.t" GLOBIGNORE="t/*tidy*:t/*compile*:$(unstables)" .PHONY: test-heavy -test-heavy: +test-heavy: node_modules $(MAKE) test-with-database HEAVY=1 TIMEOUT_M=25 PROVE_ARGS="$$HARNESS $$(grep -l HEAVY=1 t/*.t | tr '\n' ' ')" .PHONY: test-ui -test-ui: +test-ui: node_modules $(MAKE) test-with-database TIMEOUT_M=25 PROVE_ARGS="$$HARNESS t/ui/*.t" GLOBIGNORE="t/*tidy*:t/*compile*:$(unstables)" .PHONY: test-api -test-api: +test-api: node_modules $(MAKE) test-with-database TIMEOUT_M=20 PROVE_ARGS="$$HARNESS t/api/*.t" GLOBIGNORE="t/*tidy*:t/*compile*:$(unstables)" # put unstable tests in tools/unstable_tests.txt and uncomment in circle CI config to handle unstables with retries .PHONY: test-unstable -test-unstable: +test-unstable: node_modules for f in $$(cat tools/unstable_tests.txt); do $(MAKE) test-with-database COVERDB_SUFFIX=$$(echo $${COVERDB_SUFFIX}_$$f | tr '/' '_') TIMEOUT_M=10 PROVE_ARGS="$$HARNESS $$f" RETRY=5 || exit; done .PHONY: test-fullstack -test-fullstack: +test-fullstack: node_modules $(MAKE) test-with-database FULLSTACK=1 TIMEOUT_M=30 PROVE_ARGS="$$HARNESS t/full-stack.t t/33-developer_mode.t" .PHONY: test-fullstack-unstable -test-fullstack-unstable: +test-fullstack-unstable: node_modules $(MAKE) test-with-database FULLSTACK=1 TIMEOUT_M=15 PROVE_ARGS="$$HARNESS t/05-scheduler-full.t" RETRY=5 # we have apparently-redundant -I args in PERL5OPT here because Docker # only works with one and Fedora's build system only works with the other .PHONY: test-with-database -test-with-database: +test-with-database: node_modules test -d $(TEST_PG_PATH) && (pg_ctl -D $(TEST_PG_PATH) -s status >&/dev/null || pg_ctl -D $(TEST_PG_PATH) -s start) || ./t/test_postgresql $(TEST_PG_PATH) $(MAKE) test-unit-and-integration TEST_PG="DBI:Pg:dbname=openqa_test;host=$(TEST_PG_PATH)" -[ $(KEEP_DB) = 1 ] || pg_ctl -D $(TEST_PG_PATH) stop .PHONY: test-unit-and-integration -test-unit-and-integration: +test-unit-and-integration: node_modules export GLOBIGNORE="$(GLOBIGNORE)";\ export DEVEL_COVER_DB_FORMAT=JSON;\ export PERL5OPT="$(COVEROPT)$(PERL5OPT) -It/lib -I$(PWD)/t/lib -I$(PWD)/external/os-autoinst-common/lib -MOpenQA::Test::PatchDeparse";\ From cc8ac11b04aa25c26061d8cfd0d35403660f9dd4 Mon Sep 17 00:00:00 2001 From: Marius Kittler Date: Thu, 29 Feb 2024 18:41:09 +0100 Subject: [PATCH 2/2] Print a helpful error message when assets via npm are missing Assets might be missing when one just invokes `script/openqa daemon` from a Git checkout without taking care of installing npm packages first. Assets might also be missing if packaging hasn't been adapted yet after the switch to using npm has happened. This change prints an error message with a helpful suggestion in both of those cases. Related ticket: https://progress.opensuse.org/issues/155713 --- lib/OpenQA/WebAPI.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/OpenQA/WebAPI.pm b/lib/OpenQA/WebAPI.pm index de24b242786..e60c961ff50 100644 --- a/lib/OpenQA/WebAPI.pm +++ b/lib/OpenQA/WebAPI.pm @@ -78,7 +78,15 @@ sub startup ($self) { $self->asset->store->retries(5) if $Mojolicious::Plugin::AssetPack::VERSION > 2.13; # -> read assets/assetpack.def - $self->asset->process; + eval { $self->asset->process }; + if (my $assetpack_error = $@) { # uncoverable statement + $assetpack_error # uncoverable statement + .= 'If you invoked this service for development (from a Git checkout) you probably just need to' + . ' invoke "make node_modules" before running this service. If you invoked this service via a packaged binary/service' + . " then there is probably a problem with the packaging.\n" + if $assetpack_error =~ qr/could not find input asset.*node_modules/i; # uncoverable statement + die $assetpack_error; # uncoverable statement + } # set cookie timeout to 48 hours (will be updated on each request) $self->app->sessions->default_expiration(48 * 60 * 60);