fix: create runs_dir only on write paths, not in RunManager.__init__#48
Conversation
…it__ Metadata lookups (status/list/job-output/wait) invoked against the wrong project root used to leave an empty .crewster/runs tree behind before printing "Run not found". RunManager now defers directory creation to create_run/save_run_meta, and list_runs treats a missing runs_dir as "no runs" (EAFP, so a runs_dir that exists as a regular file still fails loudly). When a lookup fails with no runs recorded under the searched root, job-output and wait now hint that run metadata lives under the project root used at submit time; the hint gates on list_runs so stray entries cannot suppress it, and it phrases the remedy conditionally to avoid misdirecting fresh-project typos. Closes #44
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughRun metadata lookup paths no longer create ChangesRun lookup behavior
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
) An empty list_runs result means "no runs recorded", so only a missing runs_dir may read as empty. The docstring already claims that a runs_dir existing as a regular file fails loudly, but no test pinned it: widening the except clause (e.g. to OSError) would silently turn that corrupted state into an empty run list. The contract test raises NotADirectoryError on a runs_dir-as-file and fails on the pre-#48 is_dir() guard, which returned [] for the same state.
Summary
Metadata-lookup commands (
status,list,job-output,wait) invoked against the wrong project root used to create an empty.crewster/runstree there before printingRun not found, becauseRunManager.__init__unconditionally ranmkdir(parents=True, exist_ok=True). Directory creation now happens only on write paths, and failed lookups leave the filesystem untouched. Closes #44Changes
src/crewster/run.py: removed themkdirfromRunManager.__init__;create_runandsave_run_metaalready create their run directory withparents=True, which coversruns_dir.list_runstreats a missingruns_diras "no runs" — EAFP arounditerdir, so aruns_dirthat exists as a regular file still fails loudly.src/crewster/cli.py: new_print_run_not_foundhelper used byjob-outputandwaiton a failed lookup. When no runs are recorded under the searched root, it names that directory and notes, conditionally, that a run submitted from a different project root must be looked up with the same--project-dir/--configas at submit time. The hint gates onlist_runs(the manager's definition of a recorded run), so stray entries such as.DS_Storeor a metadata-less directory cannot suppress it.Impact
submitis unaffected (its write path creates the directory).status/list/job-output/waitlose themkdirside effect;load_run_metastill raisesFileNotFoundErrorfor a missing tree, which the id-lookup commands (status,job-output,wait) already catch, andcrewster listin a fresh project still printsNo runs found.Test plan
Invariant: a failed metadata lookup never creates
.crewster/runs.tests/test_run.py:__init__creates nothing;list_runs/find_run_by_job_id/load_run_metaon a missingruns_dirreturn[]/None/ raise without touching the filesystem;create_runandsave_run_metacreate the tree when missing.tests/test_cli.py:waitandstatuswith an unknown id andlistin a fresh project leave.crewsteruncreated; the hint fires on an empty metadata tree, survives stray non-run entries, and is suppressed when runs are recorded.pytest: 379 passed;ruff check/ruff format/pyrightclean.Notes
statusstill queries the scheduler when an id matches no local run metadata, without reporting the metadata miss; itsRun not foundbranch is unreachable for a non-empty argument. Tracked in status:Run not foundbranch is unreachable after the job-id fallback #47.find_run_by_job_idalready did. The double scan on this error path is deliberate: it keeps the emptiness check insidelist_runsinstead of threading the run list from the lookup into the printing helper.Summary by CodeRabbit
.crewsterdirectory.list,status, andwaitnow handle projects without recorded runs more cleanly.