Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions app/templates/runs/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ <h1>Import runs</h1>
<label class="field-label" for="ws-name">Workspace name</label>
<input type="text" name="name" id="ws-name" placeholder="optional — two random words otherwise" autocomplete="off" spellcheck="false" style="margin-bottom:1rem">
{% endif %}
<label class="field-label" for="path">Run folders</label>
<label class="field-label" for="path">Run folders{% if mode == 'new' %} (optional){% endif %}</label>
<div id="path-list" data-suggestions-url="{{ url_for('folder_suggestions') }}">
<div class="path-row">
<input type="text" name="path" id="path" placeholder="/path/to/jobs — or a pattern: …/jobs_*, …/**/jobs"
required autofocus autocomplete="off" spellcheck="false"
{% if mode == 'add' %}required {% endif %}autofocus autocomplete="off" spellcheck="false"
aria-describedby="path-error">
<button type="button" class="row-x" aria-label="Remove this path" hidden>×</button>
<button type="button" class="add-btn" title="Add another path"
Expand Down Expand Up @@ -248,7 +248,7 @@ <h1>Import runs</h1>
parseBtn.addEventListener('click', async () => {
const paths = typedPaths();
if (!staged.length) {
if (!paths.length) return fieldError('Enter a path, or add a folder below.');
if (!paths.length && pathForm.elements.new.value !== '1') return fieldError('Enter a path, or add a folder below.');
return pathForm.submit();
}
const fd = new FormData();
Expand Down
75 changes: 75 additions & 0 deletions app/ui_tests/test_empty_workspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""New workspace with no path makes an empty workspace; adding runs still needs a path."""
import json
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch

from ui_tests.test_routes import web
from nullius import workspace


class EmptyWorkspace(unittest.TestCase):
def setUp(self):
temporary = tempfile.TemporaryDirectory()
self.addCleanup(temporary.cleanup)
self.root = Path(temporary.name)
self.home = self.root / "workspaces"
for target in (patch.object(web.shared, "WS_HOME", str(self.home)),
patch.dict(web.shared.STATE, {"workspace": None, "roots": [], "label": "", "job_roots": []})):
target.start()
self.addCleanup(target.stop)
self.client = web.app.test_client()
with self.client.session_transaction() as session:
session["csrf"] = "empty-test"

def post(self, route, **data):
response = self.client.post(route, data={"csrf": "empty-test", **data})
self.addCleanup(response.close)
return response

def test_a_name_alone_creates_and_opens_an_empty_workspace(self):
response = self.post("/use-path", name="Scratch", path="", new="1")
self.assertEqual(response.status_code, 302)
ws = web.shared.STATE["workspace"]
self.assertEqual((ws.name, ws.label, ws.roots), ("scratch", "Scratch", []))
self.assertEqual(json.loads((self.home / "scratch/workspace.json").read_text())["roots"], [])
html = self.client.get("/runs").get_data(as_text=True)
self.assertIn("Add runs to Scratch", html)
self.assertNotIn("Nothing job-shaped", html)

def test_a_blank_name_gives_two_random_words(self):
self.post("/use-path", new="1")
ws = web.shared.STATE["workspace"]
adjective, noun = ws.name.split("-")
self.assertIn(adjective, workspace.ADJECTIVES)
self.assertIn(noun, workspace.NOUNS)

def test_adding_nothing_to_the_open_workspace_creates_nothing(self):
for route in ("/use-path", "/upload"):
with self.subTest(route=route):
self.post(route, new="0")
self.assertIsNone(web.shared.STATE["workspace"])
self.assertFalse(self.home.exists())
with self.client.session_transaction() as session:
self.assertIn("nothing to scan", str(session.get("_flashes")))

def test_a_path_still_goes_to_its_roots(self):
job = self.root / "jobs/test-run"
job.mkdir(parents=True)
(job / "config.json").write_text(json.dumps({"agents": [{"name": "fixture"}]}))
with patch.object(web.shared, "adopt_roots") as adopt:
self.post("/use-path", name="", path=str(self.root / "jobs"), new="1")
adopt.assert_called_once_with([str(self.root / "jobs")], label="", new=True)
self.assertFalse(self.home.exists())

def test_a_missing_path_creates_nothing(self):
self.post("/use-path", name="Scratch", path=str(self.root / "missing"), new="1")
self.assertIsNone(web.shared.STATE["workspace"])
self.assertFalse(self.home.exists())

def test_the_form_needs_its_token(self):
response = self.client.post("/use-path", data={"name": "Scratch", "new": "1"})
self.addCleanup(response.close)
self.assertEqual(response.status_code, 403)
self.assertFalse(self.home.exists())
10 changes: 7 additions & 3 deletions app/web/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def index():
preparing = [(jid, e) for e in mine if e.state in execution.ALIVE for jid in e.summary()["job_ids"] if jid not in have]
# a launch whose runs wrote no job yet (or never will: refused, stopped) is still shown
if not jobs and not mine:
return render_template("runs/setup.html", scanned=True, mode="add",
return render_template("runs/setup.html", scanned=bool(shared.STATE["roots"]), mode="add",
workspaces=workspace.list_all(shared.WS_HOME))
# A Harbor killed by a Stop (or dead with the run) leaves its result
# record saying trials are running; the runner's record says otherwise.
Expand Down Expand Up @@ -381,13 +381,17 @@ def _after_import(good, refused, new):
@app.route("/use-path", methods=["POST"])
def use_path():
shared._require_csrf()
new = request.form.get("new") == "1"
label = (request.form.get("name") or "").strip()
if new and not any(p.strip() for p in request.form.getlist("path")):
shared.open_workspace(workspace.create(shared.WS_HOME, [], label)) # no path: an empty workspace
return redirect(url_for("index"))
good, bad = shared.resolve_submitted_paths(request.form.getlist("path"))
if bad:
flash(shared._bad_paths_message(bad), "error")
good, refused = _readable(good)
new = request.form.get("new") == "1"
if good:
shared.adopt_roots(good, label=(request.form.get("name") or "").strip(), new=new)
shared.adopt_roots(good, label=label, new=new)
return _after_import(good, refused, new)


Expand Down
2 changes: 1 addition & 1 deletion docs/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ A count of runs leaves out the checks. The checks have a count of their own.

## Workspace

The roots you opened, the imports converted and the judgements saved; the same roots reopen the same workspace. A start with no root given reopens the workspace left open; a closed one stays closed.
The roots you opened, the imports converted and the judgements saved; the same roots reopen the same workspace. A start with no root given reopens the workspace left open; a closed one stays closed. **New workspace** with no root makes an empty workspace.

<div class="grid cards" markdown>

Expand Down
Loading