feat(mcp): queue long-running calculations

This commit is contained in:
2026-10-29 18:25:15 +08:00
parent 2865811f1b
commit 63af998045
32 changed files with 1588 additions and 72 deletions
+25
View File
@@ -0,0 +1,25 @@
import json
import pytest
from app.services.calculation_cleanup import _names, record_calculation_database
from app.algorithms._utils import calculation_temp_directory
def test_job_owned_database_ledger_survives_until_successful_cleanup(tmp_path, monkeypatch):
monkeypatch.setenv("TJWATER_CALCULATION_JOB_DIR", str(tmp_path))
name = "tjw_tmp_run_project_" + "a" * 32
record_calculation_database(name)
record_calculation_database(name)
assert _names(tmp_path) == [name]
assert json.loads((tmp_path / "databases.json").read_text()) == [name]
record_calculation_database(name, removed=True)
assert _names(tmp_path) == []
assert calculation_temp_directory("leakage") == str(tmp_path / "leakage")
@pytest.mark.parametrize("names", [["production"], ["tjw_tmp_not_random"], {"database": "production"}])
def test_cleanup_rejects_non_job_database_names(tmp_path, names):
(tmp_path / "databases.json").write_text(json.dumps(names))
with pytest.raises(ValueError):
_names(tmp_path)