Repository: cylc/cylc-uiserver (language: python)

Issue:
Fix `cylc play` service
- cylc version arg was not working
- could not play multiple workflows

Closes #524 

Should we backport this to 1.3.x?

**Check List**

- [x] I have read `CONTRIBUTING.md` and added my name as a Code Contributor.
- [x] Contains logically grouped changes (else tidy your branch by rebase).
- [x] Does not contain off-topic changes (use other PRs for other changes).
- [x] Tests are included 
- [x] `CHANGES.md` entry included if this is a change that can affect users
- [x] No docs needed
- [x] If this is a bug fix, PR should be raised against the relevant `?.?.x` branch.



Discussion / hints:
Will merge after doing a little due diligence on failing test. 

Fix patch:
diff --git a/changes.d/533.fix.md b/changes.d/533.fix.md
new file mode 100644
index 00000000..01af0f5c
--- /dev/null
+++ b/changes.d/533.fix.md
@@ -0,0 +1,1 @@
+Fixed bug introduced in 1.4.2 where playing a workflow would fail if using a Cylc environment whose name does not match `cylc-8.X.Y` exactly.
diff --git a/cylc/uiserver/resolvers.py b/cylc/uiserver/resolvers.py
index 9194b615..db3e357f 100644
--- a/cylc/uiserver/resolvers.py
+++ b/cylc/uiserver/resolvers.py
@@ -300,8 +300,8 @@ async def play(
                 log.info(f'$ {cmd_repr}')
 
                 env = os.environ.copy()
-                env.pop('CYLC_ENV_NAME', None)
                 if cylc_version:
+                    env.pop('CYLC_ENV_NAME', None)
                     env['CYLC_VERSION'] = cylc_version
 
                 # run cylc play


Test patch:
diff --git a/cylc/uiserver/tests/test_resolvers.py b/cylc/uiserver/tests/test_resolvers.py
index 6f313c6b..0ed28726 100644
--- a/cylc/uiserver/tests/test_resolvers.py
+++ b/cylc/uiserver/tests/test_resolvers.py
@@ -78,6 +78,14 @@ def test_Services_anciliary_methods(func, message, expect):
             {'CYLC_VERSION': 'top'},
             id="cylc version overrides env"
         ),
+        pytest.param(
+            [Tokens('wflow1')],
+            {},
+            {'CYLC_VERSION': 'charm', 'CYLC_ENV_NAME': 'quark'},
+            [True, "Workflow(s) started"],
+            {'CYLC_VERSION': 'charm', 'CYLC_ENV_NAME': 'quark'},
+            id="cylc env not overriden if no version specified"
+        ),
     ]
 )
 async def test_play(
@@ -97,6 +105,9 @@ async def test_play(
         expected_ret: expected return value
         expected_env: any expected environment variables
     """
+    monkeypatch.delenv('CYLC_ENV_NAME', raising=False)
+    expected_env = {**os.environ, **expected_env}
+
     for k, v in env.items():
         monkeypatch.setenv(k, v)
     monkeypatch.setattr('cylc.uiserver.resolvers.getuser', lambda: 'murray')
@@ -118,9 +129,6 @@ async def test_play(
 
     assert ret == expected_ret
 
-    expected_env = {**os.environ, **expected_env}
-    expected_env.pop('CYLC_ENV_NAME', None)
-
     for i, call_args in enumerate(mock_popen.call_args_list):
         cmd_str = ' '.join(call_args.args[0])
         assert cmd_str.startswith('cylc play')