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.
This commit is contained in:
liuhao1024 2026-07-03 05:06:09 +08:00 committed by Teknium
parent 7a5fe00244
commit fa96419993
1 changed files with 24 additions and 0 deletions

View File

@ -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."""