diff --git a/app/ui_tests/test_run_routes.py b/app/ui_tests/test_run_routes.py
index 75fc5903..8db8447c 100644
--- a/app/ui_tests/test_run_routes.py
+++ b/app/ui_tests/test_run_routes.py
@@ -447,6 +447,31 @@ def test_a_restart_reopens_the_open_workspace_and_puts_the_run_back_into_its_own
self.assertNotIn(self.jobs, workspace.load(self.home, other.name).roots)
self.assertEqual(json.loads(self.record.read_text())["workspace"], self.ws.name)
+ def test_a_rename_refiles_the_run_and_a_restart_puts_it_back_in_the_renamed_workspace(self):
+ rec = json.loads(self.record.read_text())
+ ex = execution.Execution(execution.Plan.from_dict(rec["plan"]), root=str(self.tmp / "runs"), record=rec)
+ execution.EXECUTIONS[ex.id] = ex # the run as the page holds it
+ r = self.client.post("/workspaces/rename", data={"name": self.ws.name, "label": "sharp lemur", "csrf": self.csrf},
+ headers={"Origin": "http://localhost"}); self.addCleanup(r.close)
+ self.assertEqual(r.status_code, 302)
+ self.assertEqual(json.loads(self.record.read_text())["workspace"], "sharp-lemur")
+ execution.EXECUTIONS.clear()
+ renamed = workspace.load(self.home, "sharp-lemur"); renamed.opened = "2000-01-01T00:00:00+00:00"; workspace.save(renamed)
+ other = workspace.create(self.home, [str(self.tmp / "a")], label="quiet otter")
+ web.shared.open_workspace(other)
+ self.assertEqual(self.restart().name, other.name)
+ self.assertIn(self.jobs, workspace.load(self.home, "sharp-lemur").roots)
+ self.assertNotIn(self.jobs, workspace.load(self.home, other.name).roots)
+
+ def test_a_run_filed_under_a_name_no_workspace_has_stays_out_of_the_open_one(self):
+ workspace.rename(self.home, self.ws, "sharp lemur") # its record not refiled: the name is gone
+ self.ws.opened = "2000-01-01T00:00:00+00:00"; workspace.save(self.ws)
+ other = workspace.create(self.home, [str(self.tmp / "a")], label="quiet otter")
+ web.shared.open_workspace(other)
+ self.assertEqual(self.restart().name, other.name) # the open one stays open
+ self.assertEqual(workspace.load(self.home, other.name).roots, [str(self.tmp / "a")])
+ self.assertIn(self.jobs, workspace.load(self.home, "sharp-lemur").roots)
+
def test_a_restart_leaves_a_closed_workspace_closed(self):
r = self.client.post("/change-source", data={"csrf": self.csrf}); self.addCleanup(r.close)
self.assertEqual(r.status_code, 302)
diff --git a/app/web/shared.py b/app/web/shared.py
index fb15f90d..a0575d98 100644
--- a/app/web/shared.py
+++ b/app/web/shared.py
@@ -335,11 +335,11 @@ def adopt_roots(roots, label="", new=False, into=""):
Without a label, roots that already have a workspace reopen it — so a
restart with the same argv lands in the same place, cache and all.
``into``: the workspace to add them to while it exists, left closed
- unless it is open already.
+ unless it is open already; once it is gone, never the open one.
"""
ws = STATE["workspace"]
if into and not (ws and ws.name == into):
- ws = workspace.load(WS_HOME, into) or ws
+ ws = workspace.load(WS_HOME, into)
if ws and not new:
ws.roots = list(ws.roots) + [r for r in roots if r not in ws.roots]
workspace.save(ws)
@@ -348,7 +348,8 @@ def adopt_roots(roots, label="", new=False, into=""):
return ws
ws = None if label else workspace.find_by_roots(WS_HOME, roots, besides=execution.runs_root())
ws = ws or workspace.create(WS_HOME, roots, label)
- open_workspace(ws)
+ if new or not into or STATE["workspace"] is None: # a gone ``into`` leaves the open workspace open
+ open_workspace(ws)
return ws
diff --git a/app/web/workspaces.py b/app/web/workspaces.py
index bd239703..febc81eb 100644
--- a/app/web/workspaces.py
+++ b/app/web/workspaces.py
@@ -128,8 +128,8 @@ def workspace_refresh():
def workspace_rename():
"""Rename the workspace a row names, open or not: its label, and its
directory moved to the label's slug (``workspace.rename``). The open one
- is read from where it is now. Takes the form token: a rename moves a
- directory."""
+ is read from where it is now, and the runs filed under it are filed
+ under its new name. Takes the form token: a rename moves a directory."""
shared._require_csrf()
open_ws = shared.STATE["workspace"]
name = request.form.get("name") or (open_ws.name if open_ws is not None else "")
@@ -140,11 +140,15 @@ def workspace_rename():
if ws is None:
flash(Markup(f'No workspace called {escape(name)}.'), "error")
elif label:
+ old = ws.name
try:
workspace.rename(shared.WS_HOME, ws, label)
except OSError as exc:
flash(Markup(f'{escape(ws.label)} could not be renamed: {escape(exc.strerror or str(exc))}.'), "error")
return redirect(back)
+ for ex in execution.EXECUTIONS.values():
+ if old != ws.name and ex.workspace == old:
+ ex.file_under(ws.name) # a restart puts the run back in it by this name
if is_open:
shared.open_workspace(ws) # its imports moved with it: read from where it is now
return redirect(back)
diff --git a/docs/builder.md b/docs/builder.md
index 81db5052..d049cef3 100644
--- a/docs/builder.md
+++ b/docs/builder.md
@@ -116,7 +116,7 @@ and Delete work only from a browser on the application host.
| Docker or Podman | The engine must answer `ps` (`docker ps`, or `podman ps` for the standard's container backend), or the run stops before it starts |
| Stop | Ends the current part (exit 130), records `stopped`; the next part never starts |
| Delete launch | On the launch in Runs, *By launch*, once every run of it has ended; asks first. The job page links to it. Deletes each run's `//` (a shard per machine included), every job of the launch, their judgements in every workspace, and each run's copy on its host when ticked. A run still going is refused: stop it first. A launch with jobs from elsewhere has no Delete |
-| Restart of Nullius | `execution.restore` reattaches from `runs//run.json`; the job goes back into the workspace it started in, while that workspace exists, without opening it. The workspace open before the restart opens again |
+| Restart of Nullius | `execution.restore` reattaches from `runs//run.json`; the job goes back into the workspace it started in, under the name a rename gave it, while that workspace exists, without opening it. The workspace open before the restart opens again |
| Cannot run from the page | Generated tasks and custom agents are not supported by Run |
| Refused | Reads *refused* on the runs page, with why; the job was never written |
| Files | `//`: script, log, `run.json`, `jobs/`; default `runs/` under the user data directory (`nullius paths`) |