Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add smoke tests scripts to evaluate node.js dependency within built docker image #561

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Changes:

Fixes:
------
- No change.
- Fix missing Node.js requirement in built Docker image in order to evaluate definitions that employ
`CWL` ``InlineJavascriptRequirement``, such as ``valueFrom`` employed for numeric ``Enum`` input type validation.

.. _changes_4.31.0:

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ docker-test: docker-build stop ## execute smoke test of the built images (valida
@curl localhost:4001 | grep "Weaver Information" || \
( docker-compose $(DOCKER_TEST_COMPOSES) logs weaver worker || true && \
docker-compose $(DOCKER_TEST_COMPOSES) stop; exit 1 )
docker-compose $(DOCKER_TEST_COMPOSES) exec weaver bash /tests/run_tests.sh
docker-compose $(DOCKER_TEST_COMPOSES) stop

.PHONY: docker-stat
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile-base
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
netbase \
gcc \
git \
nodejs \
&& pip install --no-cache-dir --upgrade -r requirements-sys.txt \
&& pip install --no-cache-dir -r requirements.txt \
&& pip install --no-cache-dir -e ${APP_DIR} \
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ replace = LABEL version="{new_version}"
addopts =
--strict-markers
--tb=native
--ignore=tests/smoke
weaver/
log_cli = false
log_level = DEBUG
Expand Down
1 change: 1 addition & 0 deletions tests/smoke/docker-compose.smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- "4001:4001"
volumes:
- ../../config/weaver.ini.example:/opt/local/src/weaver/config/weaver.ini
- ./tests:/tests
networks:
- default
restart: "no"
Expand Down
4 changes: 4 additions & 0 deletions tests/smoke/tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

pip install pytest
pytest /tests -vvv
54 changes: 54 additions & 0 deletions tests/smoke/tests/test_cwl_nodejs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
"""
Run operations specifically within the built Docker container to ensure JavaScript runtime dependencies are available.
"""

import pytest
from cwl_utils import expression
from cwltool.process import get_schema
from cwltool.validate_js import validate_js_expressions

from weaver.processes.constants import CWL_REQUIREMENT_INLINE_JAVASCRIPT


def test_cwl_nodejs(caplog: pytest.LogCaptureFixture) -> None:
"""
Run a CWL operation that requires Node.js to be evaluated.

If JavaScript cannot be parsed and executed in the Docker container, then some requirements are missing.
"""
tool = {
"cwlVersion": "v1.0",
"class": "CommandLineTool",
"baseCommand": "echo",
"requirements": [
{
"class": CWL_REQUIREMENT_INLINE_JAVASCRIPT,
}
],
"inputs": [
{
"id": "test",
"inputBinding": {
"valueFrom": "${ let x = self + 1; return x; }"
}
}
],
"outputs": {"output": "stdout"}
}
schema = get_schema(tool["cwlVersion"])[1]
clt_schema = schema.names["org.w3id.cwl.cwl.CommandLineTool"]
validate_js_expressions(tool, clt_schema) # type: ignore

out = expression.do_eval(
tool["inputs"][0]["inputBinding"]["valueFrom"],
{tool["inputs"][0]["id"]: tool["inputs"][0]},
tool["requirements"],
None,
None,
{},
context=1, # value passed as input
)

assert "JSHINT" in caplog.text
assert out == 2 # JS 'self + 1'
Loading