Skip to content

Commit 476695c

Browse files
papysansclaude
andcommitted
fix(api): 收紧 one-shot 响应字段契约
Align the one-shot book response payload with the canonical batch_direction request field so clients no longer depend on the legacy prompt key. Also rename the targeted regression tests to match the tightened contract and assert that prompt is absent. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3e640d8 commit 476695c

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

backend/api/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4615,7 +4615,7 @@ async def book_stage_callback(
46154615
response_payload = {
46164616
"project_id": project_id,
46174617
"mode": req.mode.value,
4618-
"prompt": req.batch_direction.strip(),
4618+
"batch_direction": req.batch_direction.strip(),
46194619
"continuation_mode": req.continuation_mode,
46204620
"generated_chapters": len(created),
46214621
"chapters": created,

backend/tests/test_api_smoke.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ def test_one_shot_book_stream_generation(self):
11871187
self.assertIn("event: chapter_chunk", payload)
11881188
self.assertIn("event: done", payload)
11891189

1190-
def test_one_shot_book_accepts_batch_direction_alias(self):
1190+
def test_one_shot_book_returns_canonical_batch_direction_field(self):
11911191
project_id = self._create_project()
11921192
batch_res = self.client.post(
11931193
f"/api/projects/{project_id}/one-shot-book",
@@ -1199,10 +1199,12 @@ def test_one_shot_book_accepts_batch_direction_alias(self):
11991199
},
12001200
)
12011201
self.assertEqual(batch_res.status_code, 200)
1202-
self.assertEqual(batch_res.json()["generated_chapters"], 1)
1202+
payload = batch_res.json()
1203+
self.assertEqual(payload["generated_chapters"], 1)
12031204
self.assertEqual(
1204-
batch_res.json()["prompt"], "主角在雪夜被背叛后潜伏反击,最终揪出幕后主使。"
1205+
payload["batch_direction"], "主角在雪夜被背叛后潜伏反击,最终揪出幕后主使。"
12051206
)
1207+
self.assertNotIn("prompt", payload)
12061208

12071209
def test_consistency_p0_check_endpoint(self):
12081210
project_id = self._create_project(taboo_constraints=["禁止词"])

backend/tests/test_v2_semantics.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_project_creation_writes_project_type_and_synopsis_into_identity(self):
4949
self.assertIn("Story Synopsis", identity)
5050
self.assertIn("主角在霜城发现王室血脉秘密", identity)
5151

52-
def test_one_shot_book_accepts_batch_direction_alias(self):
52+
def test_one_shot_book_returns_canonical_batch_direction_field(self):
5353
create_res = self.client.post(
5454
"/api/projects",
5555
json={
@@ -75,7 +75,8 @@ def test_one_shot_book_accepts_batch_direction_alias(self):
7575
self.assertEqual(batch_res.status_code, 200)
7676
payload = batch_res.json()
7777
self.assertEqual(payload["generated_chapters"], 1)
78-
self.assertEqual(payload["prompt"], "主角在雪夜被背叛后潜伏反击,最终揪出幕后主使。")
78+
self.assertEqual(payload["batch_direction"], "主角在雪夜被背叛后潜伏反击,最终揪出幕后主使。")
79+
self.assertNotIn("prompt", payload)
7980

8081
def test_one_shot_book_accepts_scope_field(self):
8182
create_res = self.client.post(

0 commit comments

Comments
 (0)