diff --git a/app/nullius/workspace.py b/app/nullius/workspace.py index a8f9a9e2..71064b12 100644 --- a/app/nullius/workspace.py +++ b/app/nullius/workspace.py @@ -335,6 +335,24 @@ def _head(job_dir: str) -> str: return "\n".join(parts) +def heads(roots) -> tuple: + """``_head`` of each of *roots* and of each entry in it: what + ``parse.find_job_dirs`` over them, and the parse of an ended job found + there, can change by. A page's summary of ended jobs is kept while this is. + shortcut: a change inside a trial folder alone (a trial's result.json, or + the first one of a job without events.jsonl) or a link retargeted is not + seen; key on ``signature`` of each job if those must show.""" + out = [] + for root in roots: + try: + names = sorted(os.listdir(root)) + except OSError: + out.append((root, None)) + continue + out.append((root, _head(root), tuple((n, _head(os.path.join(root, n))) for n in names))) + return tuple(out) + + def _ended(job: parse.Job) -> bool: """Its result records a finish and nothing running or pending: its trials are final.""" return job.finished_at is not None and job.state == "finished" diff --git a/app/tests/test_workspace.py b/app/tests/test_workspace.py index 35f792db..e1a15adb 100644 --- a/app/tests/test_workspace.py +++ b/app/tests/test_workspace.py @@ -383,6 +383,20 @@ def test_a_job_no_run_writes_is_read_by_its_head(self): again, from_cache = workspace.load_job(self.ws, self.job_dir, runs={"job-b": None}) self.assertIs(again, first); self.assertTrue(from_cache) + def test_heads_move_with_a_job_added_removed_or_rewritten_not_with_a_trial(self): + before = workspace.heads([self.root]) + _write_json(os.path.join(self.job_dir, "tau3-bench__t0__abc", "result.json"), {"rewritten": True}) + self.assertEqual(workspace.heads([self.root]), before) # the shortcut's limit + _write_json(os.path.join(self.job_dir, "result.json"), {"id": "j1", "stats": {"n_running_trials": 1}}) + rewritten = workspace.heads([self.root]) + self.assertNotEqual(rewritten, before) + _job_dir(self.root, "job-b") + self.assertNotEqual(workspace.heads([self.root]), rewritten) + shutil.rmtree(os.path.join(self.root, "job-b")) + self.assertNotEqual(workspace.heads([self.root]), rewritten) # the root's own mtime moved + gone = os.path.join(self.root, "gone") + self.assertEqual(workspace.heads([gone]), ((gone, None),)) + def test_index_lists_runs_without_a_parse(self): self.assertEqual(workspace.job_index(self.ws), {}) workspace.load_job(self.ws, self.job_dir) diff --git a/app/ui_tests/test_run_routes.py b/app/ui_tests/test_run_routes.py index a585fe93..73a71f58 100644 --- a/app/ui_tests/test_run_routes.py +++ b/app/ui_tests/test_run_routes.py @@ -975,6 +975,22 @@ def test_runs_and_checks_are_counted_alike_on_both_pages(self): self.assertEqual([self.cells(rows[key])[c] for c in ("runs", "checks")], ["1", "0"]) # the merge stands for its two shards self.assertEqual([self.cells(rows[f"run:{refused.id}"])[c] for c in ("runs", "checks", "state")], ["1", "1", "refused"]) + def test_launches_kept_between_loads_follow_the_disk(self): + from tests.test_feasibility import write_job + rec = self.record("r3", "running") + said = lambda: [self.cells(self.rows()[f"run:{rec.id}"])[c] for c in ("runs", "checks", "state")] + self.assertEqual(said(), ["1", "1", "running"]) + rec.state = "done" # a run ending + self.assertEqual(said(), ["1", "1", "finished"]) + self.assertIn("last", web.runs._EVERY) # kept: every job has ended + write_job(rec.jobs, "r3-nop", "my-agent", {"a": 1}) # a job added: no check after all + self.assertEqual(said(), ["2", "0", "finished"]) + shutil.rmtree(os.path.join(rec.jobs, "r3-nop")) # and removed: named, not written + self.assertEqual(said(), ["1", "1", "finished"]) + cfg = os.path.join(rec.jobs, "r3-a", "config.json") # a job rewritten in place + self._write_json(cfg, {**json.loads(Path(cfg).read_text()), "agents": [{"name": "oracle"}]}) + self.assertEqual(said(), ["0", "2", "finished"]) + def test_no_launch_is_one_line(self): execution.EXECUTIONS.clear() self.assertIn('
1 run · 2 checks · ", ask) # the folder's Delete counts its run alike + def test_counts_kept_between_loads_follow_the_disk(self): + from tests.test_feasibility import write_job + other, jobs = self.other(), str(self.run_dir / "jobs") + counts = lambda: (self.cell(other, 2), self.cell(other, 3), self.cell(other, 5)) + self.assertEqual(counts(), ("2", "0", "1")) + self.assertIn(other.name, web.workspaces._COUNTS) # kept: its jobs have ended + self.assertEqual(counts(), ("2", "0", "1")) + write_job(jobs, "r1-c", "nop", {"a": 0}) # a job added + self.assertEqual(counts(), ("2", "1", "1")) + shutil.rmtree(os.path.join(jobs, "r1-c")) # and removed + self.assertEqual(counts(), ("2", "0", "1")) + cfg = os.path.join(jobs, "r1-b", "config.json") # a job rewritten in place + self._write_json(cfg, {**json.loads(Path(cfg).read_text()), "agents": [{"name": "oracle"}]}) + self.assertEqual(counts(), ("1", "1", "1")) + rec = LaunchesPage.record(self, "r9") # a launch added to it: its roots change + other.roots.append(rec.jobs); workspace.save(other) + self.assertEqual(counts(), ("2", "2", "2")) + del execution.EXECUTIONS["r9"] # the run records change + self.assertEqual(counts(), ("2", "1", "1")) + def test_launches_count_as_the_filtered_launches_page(self): bare = workspace.create(self.home, [str(self.tmp / "none")], label="bare") rows = re.findall(r'