Skip to content

Commit

Permalink
Cylc VR: Pass validate a copy of the options object to
Browse files Browse the repository at this point in the history
prevent changes made to the options by validate affecting
subsequent steps.
  • Loading branch information
wxtim committed Aug 22, 2024
1 parent 2e3ba22 commit d97e9f5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes.d/6316.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent validate step of VR changing CLI options.
7 changes: 6 additions & 1 deletion cylc/flow/scripts/validate_reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
in the installed workflow to ensure the change can be safely applied.
"""

from copy import copy
import sys
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -171,7 +172,11 @@ async def vr_cli(parser: COP, options: 'Values', workflow_id: str):

# Run cylc validate
log_subcommand('validate --against-source', workflow_id)
await cylc_validate(parser, options, workflow_id)

# Copy options in case validate decides to store information
# in the options object:
val_opts = copy(options)
await cylc_validate(parser, val_opts, workflow_id)

# Unset options that do not apply after validation:
delattr(options, 'against_source')
Expand Down
38 changes: 38 additions & 0 deletions tests/functional/cylc-combination-scripts/09-vr-icp-now.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

#------------------------------------------------------------------------------
# Ensure that validate step of Cylc VR cannot change the options object.
# See https://github.com/cylc/cylc-flow/issues/6262

. "$(dirname "$0")/test_header"
set_test_number 2

WORKFLOW_ID=$(workflow_id)

cp -r "${TEST_SOURCE_DIR}/${TEST_NAME_BASE}/flow.cylc" .

run_ok "${TEST_NAME_BASE}-vip" \
cylc vip . \
--workflow-name "${WORKFLOW_ID}" \
--no-detach \
--no-run-name

echo "# Some Comment" >> flow.cylc

run_ok "${TEST_NAME_BASE}-vr" \
cylc vr "${WORKFLOW_ID}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[scheduling]
initial cycle point = now
[[graph]]
PT1M = foo
[runtime]
[[foo]]
script = cylc stop "${CYLC_WORKFLOW_ID}"

0 comments on commit d97e9f5

Please sign in to comment.