1414# You should have received a copy of the GNU General Public License
1515# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17+ from pathlib import Path
18+ import sqlite3
1719from typing import Callable
1820from unittest .mock import Mock
1921
20-
22+ from cylc . flow . workflow_files import WorkflowFiles
2123from cylc .flow .xtriggers .workflow_state import workflow_state
2224from ..conftest import MonkeyMock
2325
@@ -38,3 +40,47 @@ def test_inferred_run(tmp_run_dir: Callable, monkeymock: MonkeyMock):
3840 _ , results = workflow_state (id_ , task = 'precious' , point = '3000' )
3941 mock_db_checker .assert_called_once_with (cylc_run_dir , expected_workflow_id )
4042 assert results ['workflow' ] == expected_workflow_id
43+
44+
45+ def test_back_compat (tmp_run_dir ):
46+ """Test workflow_state xtrigger backwards compatibility with Cylc 7
47+ database."""
48+ id_ = 'celebrimbor'
49+ c7_run_dir : Path = tmp_run_dir (id_ )
50+ (c7_run_dir / WorkflowFiles .FLOW_FILE ).rename (
51+ c7_run_dir / WorkflowFiles .SUITE_RC
52+ )
53+ db_file = c7_run_dir / 'log' / 'db'
54+ db_file .parent .mkdir (exist_ok = True )
55+ # Note: cannot use CylcWorkflowDAO here as creating outdated DB
56+ conn = sqlite3 .connect (str (db_file ))
57+ try :
58+ conn .execute (r"""
59+ CREATE TABLE suite_params(key TEXT, value TEXT, PRIMARY KEY(key));
60+ """ )
61+ conn .execute (r"""
62+ CREATE TABLE task_states(
63+ name TEXT, cycle TEXT, time_created TEXT, time_updated TEXT,
64+ submit_num INTEGER, status TEXT, PRIMARY KEY(name, cycle)
65+ );
66+ """ )
67+ conn .executemany (
68+ r'INSERT INTO "suite_params" VALUES(?,?);' ,
69+ [('cylc_version' , '7.8.12' ),
70+ ('cycle_point_format' , '%Y' ),
71+ ('cycle_point_tz' , 'Z' )]
72+ )
73+ conn .execute (r"""
74+ INSERT INTO "task_states" VALUES(
75+ 'mithril','2012','2023-01-30T18:19:15Z','2023-01-30T18:19:15Z',
76+ 0,'succeeded'
77+ );
78+ """ )
79+ conn .commit ()
80+ finally :
81+ conn .close ()
82+
83+ satisfied , _ = workflow_state (id_ , task = 'mithril' , point = '2012' )
84+ assert satisfied
85+ satisfied , _ = workflow_state (id_ , task = 'arkenstone' , point = '2012' )
86+ assert not satisfied
0 commit comments