feat(submit): confirm defaults instead of removing them
Restore defaults for queue/executor_memory/executor_cores/num_executors in prepare_submit_job, but require the caller to explicitly confirm them. If any defaulted field is omitted, the route returns HTTP 400 listing the defaults and asks the caller to resubmit with explicit values. app_name remains required (no meaningful default). extra_args remains optional. Tests cover rejection of unconfirmed defaults and acceptance of explicitly confirmed defaults.
This commit is contained in:
@@ -104,6 +104,54 @@ def test_prepare_submit_job_works_via_body(tmp_path):
|
||||
assert body["parameters"]["master"] == "yarn" # snapshotted from connection
|
||||
|
||||
|
||||
def test_prepare_rejects_unconfirmed_defaults(tmp_path):
|
||||
c = TestClient(app)
|
||||
c.post("/save_connection", json={"name": "prod", "master": "yarn"})
|
||||
script = tmp_path / "demo.py"
|
||||
script.write_text("print('hi')\n")
|
||||
r = c.post(
|
||||
"/prepare_submit_job",
|
||||
json={
|
||||
"connection": "prod",
|
||||
"script_path": str(script),
|
||||
"app_name": "test-app",
|
||||
},
|
||||
)
|
||||
assert r.status_code == 400
|
||||
detail = r.json()["detail"]
|
||||
assert "Please confirm default values" in detail
|
||||
assert "queue='default'" in detail
|
||||
assert "executor_memory='4G'" in detail
|
||||
assert "executor_cores=2" in detail
|
||||
assert "num_executors=2" in detail
|
||||
|
||||
|
||||
def test_prepare_accepts_confirmed_defaults(tmp_path):
|
||||
c = TestClient(app)
|
||||
c.post("/save_connection", json={"name": "prod", "master": "yarn"})
|
||||
script = tmp_path / "demo.py"
|
||||
script.write_text("print('hi')\n")
|
||||
r = c.post(
|
||||
"/prepare_submit_job",
|
||||
json={
|
||||
"connection": "prod",
|
||||
"script_path": str(script),
|
||||
"queue": "default",
|
||||
"executor_memory": "4G",
|
||||
"executor_cores": 2,
|
||||
"num_executors": 2,
|
||||
"app_name": "test-app",
|
||||
},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["status"] == "PENDING"
|
||||
assert body["parameters"]["queue"] == "default"
|
||||
assert body["parameters"]["executor_memory"] == "4G"
|
||||
assert body["parameters"]["executor_cores"] == 2
|
||||
assert body["parameters"]["num_executors"] == 2
|
||||
|
||||
|
||||
def test_prepare_rejects_nonexistent_script_path_with_400():
|
||||
"""MCP clients should see a clean 400 with a remediation hint, not a 500."""
|
||||
c = TestClient(app)
|
||||
|
||||
@@ -4,11 +4,23 @@ import pytest
|
||||
from spark_executor.tools.requests import PrepareSubmitJobRequest
|
||||
|
||||
|
||||
def test_prepare_submit_job_request_requires_all_confirmed_parameters():
|
||||
def test_prepare_submit_job_request_requires_connection_script_path_and_app_name():
|
||||
with pytest.raises(ValueError):
|
||||
PrepareSubmitJobRequest(connection="prod", script_path="/tmp/x.py")
|
||||
|
||||
|
||||
def test_prepare_submit_job_request_restores_defaults_for_queue_and_resources():
|
||||
req = PrepareSubmitJobRequest(
|
||||
connection="prod",
|
||||
script_path="/tmp/x.py",
|
||||
app_name="test-app",
|
||||
)
|
||||
assert req.queue == "default"
|
||||
assert req.executor_memory == "4G"
|
||||
assert req.executor_cores == 2
|
||||
assert req.num_executors == 2
|
||||
|
||||
|
||||
def test_prepare_submit_job_request_accepts_extra_args():
|
||||
req = PrepareSubmitJobRequest(
|
||||
connection="prod",
|
||||
|
||||
@@ -112,6 +112,25 @@ def test_prepare_requires_explicit_app_name(monkeypatch, real_script):
|
||||
submit.prepare_submit_job(connection="prod", script_path=str(real_script))
|
||||
|
||||
|
||||
def test_prepare_accepts_restored_defaults(monkeypatch, real_script):
|
||||
monkeypatch.setattr(submit, "run_spark_submit", lambda cmd: None)
|
||||
out = submit.prepare_submit_job(
|
||||
connection="prod",
|
||||
script_path=str(real_script),
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
app_name="test-app",
|
||||
)
|
||||
assert out["status"] == "PENDING"
|
||||
p = submit.pending_store.get(_last_pending_id())
|
||||
assert p.queue == "default"
|
||||
assert p.executor_memory == "4G"
|
||||
assert p.executor_cores == 2
|
||||
assert p.num_executors == 2
|
||||
|
||||
|
||||
def test_prepare_snapshots_extra_args(monkeypatch, real_script):
|
||||
monkeypatch.setattr(submit, "run_spark_submit", lambda cmd: None)
|
||||
submit.prepare_submit_job(
|
||||
|
||||
Reference in New Issue
Block a user