diff --git a/app/nullius/runs/parse.py b/app/nullius/runs/parse.py index 7a1c9acfc..89a49756e 100644 --- a/app/nullius/runs/parse.py +++ b/app/nullius/runs/parse.py @@ -34,7 +34,7 @@ # The shape this module produces. A workspace caches parsed Jobs keyed on it, # so bump it when a Trial or Job field is added, renamed or means something # new — otherwise a cache written by the old parse is read back as current. -SCHEMA = "34" +SCHEMA = "35" # What a rate-limit record in `agent/gateway.log` looks like. The agent's SDK # retries a 429 below the harness, so a limit the run survived leaves nothing in result.json — @@ -913,6 +913,9 @@ def find_job_dirs(roots, strict=None) -> list[str]: def add(path: str) -> None: real = os.path.realpath(path) + tidy = os.path.normpath(path) # `pair/`, as a glob `pair/**` gives it, is `pair` to every reader, + if os.path.realpath(tidy) == real: # unless `..` after a link would make it another folder + path = tidy if real not in seen: seen.add(real) found.append(path) @@ -1366,7 +1369,7 @@ def parse_job(job_dir: str, reuse=None, trials: bool = True) -> Job: dataset, n_tasks = "", 0 job = Job( - job_id=os.path.basename(job_dir), + job_id=os.path.basename(os.path.abspath(job_dir)), # `pair/` and `pair/.` are `pair` too dir=job_dir, model_name=model, dataset=os.path.basename(dataset.rstrip("/")) if dataset else "", @@ -1535,7 +1538,7 @@ def views_of(jobs, folder: str, within: str = "") -> list[tuple]: first.setdefault(j.job_id, j) real = os.path.realpath(within) if within else "" return [(j, first[j.job_id] is j) for j in jobs if j.job_id.rpartition("~")[0] == folder - and os.path.basename(os.path.normpath(j.dir)) == folder and (not real or os.path.realpath(j.dir) == real)] + and os.path.basename(os.path.abspath(j.dir)) == folder and (not real or os.path.realpath(j.dir) == real)] def view_of_trial(views, trial_name: str): diff --git a/app/nullius/runs/uid.py b/app/nullius/runs/uid.py index 53daf4c74..24304e4fe 100644 --- a/app/nullius/runs/uid.py +++ b/app/nullius/runs/uid.py @@ -76,8 +76,9 @@ def facts(job_dir: str, cfg: dict, res: dict): pending. The start is ``result.json``'s only, which nothing later rewrites.""" std = cfg.get("standard") if isinstance(cfg.get("standard"), dict) else {} agents = [a for a in cfg.get("agents") or [] if isinstance(a, dict)] + folder = os.path.basename(os.path.abspath(job_dir)) if isinstance(cfg.get("harness"), str): # an import from before nullius.source: its folder and recorded source - return {"v": 1, "format": cfg["harness"], "folder": os.path.basename(job_dir), + return {"v": 1, "format": cfg["harness"], "folder": folder, "source": str(_recorded_source(cfg) or "")} start = str(res["started_at"]) if res.get("started_at") else None if std and not res: @@ -85,13 +86,13 @@ def facts(job_dir: str, cfg: dict, res: dict): if start is None and not _has_trial(job_dir): return None if std: - return {"v": 1, "format": "standard", "folder": os.path.basename(job_dir), + return {"v": 1, "format": "standard", "folder": folder, "benchmark": str(std.get("benchmark") or ""), "plugged": str(std.get("plugged") or ""), "model": str((agents[0] if agents else {}).get("model_name") or ""), "launch": str(std.get("launch") or ""), "shard": json.dumps(std.get("shard"), sort_keys=True) if std.get("shard") else "", "start": start or ""} - return {"v": 1, "format": "harbor", "folder": os.path.basename(job_dir), "job_name": str(cfg.get("job_name") or ""), + return {"v": 1, "format": "harbor", "folder": folder, "job_name": str(cfg.get("job_name") or ""), "agents": json.dumps([[str(a.get("name") or a.get("import_path") or ""), str(a.get("model_name") or "")] for a in agents]), "datasets": json.dumps([str(d.get("name") or d.get("path") or "") for d in cfg.get("datasets") or [] diff --git a/app/tests/test_cli.py b/app/tests/test_cli.py index fb81140d2..7a9e4e43d 100644 --- a/app/tests/test_cli.py +++ b/app/tests/test_cli.py @@ -185,6 +185,15 @@ def test_a_job_folder_of_several_agents_gives_its_views_as_its_page_does(self): out = self.sh("runs.cli", "show", self.tmp, "pair", "t__b") self.assertEqual(out.returncode, 0, out.stderr) self.assertTrue(out.stdout.startswith("pair~b-m-2/t__b\n"), out.stdout) + # the folder as the root, however spelled: the same ids, and the same identity + for root in (job, job + os.sep, os.path.join(job, ".")): + self.assertEqual(self.sh("runs.cli", "list", root).stdout, "pair~a-m-1\npair~b-m-2\n", root) + out = self.sh("runs.cli", "show", root, "pair~a-m-1") + self.assertEqual(out.returncode, 0, out.stderr) + self.assertTrue(out.stdout.startswith("pair~a-m-1\n"), out.stdout) + self.assertEqual({j.uid for root in (job, job + os.sep) for j in parse.load_all([root])}, + {j.uid for j in parse.load_all([job])}) + self.assertGreaterEqual(int(parse.SCHEMA), 35) # a job cached with the empty id is read again # a trial of an agent its config does not list: the folder's own job, beside its agents' runs os.makedirs(os.path.join(job, "t__z")) with open(os.path.join(job, "t__z", "result.json"), "w", encoding="utf-8") as fh: @@ -202,6 +211,16 @@ def _harbor(self, name, agents, trials, started): with open(os.path.join(self.tmp, name, path), "w", encoding="utf-8") as fh: json.dump(doc, fh) + def test_a_root_through_a_link_then_up_lists_the_job_it_reaches(self): + # `empty/via` links to `real/pair/child`: `empty/via/../nested` is `real/pair/nested`, not `empty/nested` + self._harbor("real/pair/nested", [("a", "m/1")], [("a__t", "a")], "2026-01-01T00:00:00+00:00") + os.makedirs(os.path.join(self.tmp, "real", "pair", "child")) + os.makedirs(os.path.join(self.tmp, "empty")) + os.symlink(os.path.join(self.tmp, "real", "pair", "child"), os.path.join(self.tmp, "empty", "via")) + for root in ("empty/via/../nested", "empty/via/.."): + out = self.sh("runs.cli", "list", os.path.join(self.tmp, root)) + self.assertEqual((out.returncode, out.stdout), (0, "nested\n"), (root, out.stderr)) + def test_a_view_id_a_newer_folder_also_holds_opens_what_the_page_opens(self): # the page takes the first job of an id in the order the folders are found, not the newest self._harbor("duo", [("a", "m/1"), ("b", "m/2")], [("a__t", "a"), ("b__t", "b")], "2026-01-01T00:00:00+00:00") diff --git a/app/ui_tests/test_judgement_follows_job.py b/app/ui_tests/test_judgement_follows_job.py index 010b0b435..01200668b 100644 --- a/app/ui_tests/test_judgement_follows_job.py +++ b/app/ui_tests/test_judgement_follows_job.py @@ -110,9 +110,15 @@ def test_a_batch_copies_the_older_records_of_the_workspace_asked_and_a_folded_ru self.assertFalse((self.tmp / "data" / "judgements" / jx.uid).exists()) def test_a_record_kept_before_that_two_jobs_of_one_name_may_own_is_copied_by_neither_save(self): - copy_job(self.tmp / "one" / "job-x", "2026-01-01T00:00:00Z") - copy_job(self.tmp / "two" / "job-x", "2026-02-02T00:00:00Z") - both = workspace.create(web.shared.WS_HOME, [str(self.tmp / "one"), str(self.tmp / "two")], "Both") + for spelt in ("", os.sep): # the job itself a root, as `job-x/**` gives it + with self.subTest(root=f"job-x{spelt}"): + self._copied_by_neither(self.tmp / ("slash" if spelt else "plain"), spelt) + + def _copied_by_neither(self, tmp, spelt): + copy_job(tmp / "one" / "job-x", "2026-03-03T00:00:00Z" if spelt else "2026-01-01T00:00:00Z") + copy_job(tmp / "two" / "job-x", "2026-04-04T00:00:00Z" if spelt else "2026-02-02T00:00:00Z") + roots = [str(tmp / "one") if not spelt else str(tmp / "one" / "job-x") + spelt, str(tmp / "two")] + both = workspace.create(web.shared.WS_HOME, roots, "Both" + spelt.replace(os.sep, "-slash")) web.shared.open_workspace(both) old = Path(both.dir) / "judgements" / "job-x"; old.mkdir(parents=True) (old / f"{TRIAL}.json").write_text(json.dumps({Q.VERSION: {"questions": Q.VERSION, "answers": {"kept": {"choice": "x"}},