From fa9641999347c22725e0800b0187277eafa97cfb Mon Sep 17 00:00:00 2001 From: liuhao1024 Date: Fri, 3 Jul 2026 05:06:09 +0800 Subject: [PATCH] test(cron): add _build_job_prompt extra_prompt regression tests Pins the scheduler-boundary contract: extra_prompt is appended under '## Run Context', does not mutate job['prompt'], and the header is absent when extra_prompt is omitted. Addresses review feedback from harjothkhara on PR #57342. --- tests/cron/test_scheduler.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/cron/test_scheduler.py b/tests/cron/test_scheduler.py index 76314f8324e51..288610165601c 100644 --- a/tests/cron/test_scheduler.py +++ b/tests/cron/test_scheduler.py @@ -1936,6 +1936,30 @@ class TestMultiTargetDeliveryContinuesOnFailure: assert "b@example.com" in result assert mock_pool.submit.call_count == 2 +class TestBuildJobPromptExtraPrompt: + """Regression: _build_job_prompt merges extra_prompt into the assembled prompt.""" + + def test_extra_prompt_appended_with_header(self): + """extra_prompt appears under a '## Run Context' header.""" + job = {"prompt": "stored prompt"} + result = _build_job_prompt(job, extra_prompt="CONTEXT: client=Foo") + assert "stored prompt" in result + assert "## Run Context" in result + assert "CONTEXT: client=Foo" in result + + def test_extra_prompt_does_not_mutate_job(self): + """The job dict's 'prompt' field must remain unchanged.""" + job = {"prompt": "original"} + _build_job_prompt(job, extra_prompt="transient context") + assert job["prompt"] == "original" + + def test_no_extra_prompt_omits_header(self): + """Without extra_prompt, no '## Run Context' header is injected.""" + job = {"prompt": "just the stored prompt"} + result = _build_job_prompt(job) + assert "## Run Context" not in result + assert "just the stored prompt" in result + class TestSetCronSessionTitle: """Robust cron session titling: #50535/#50536/#50537."""