mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +08:00
将请求体可变状态从 {"body": dict} 字典容器重构为独立的
MutableRequestBodyState 类,统一管理 original_body / current_body /
build_attempt_body / rectify 等语义,消除各层通过 ref["body"] 间接
读写的隐式约定。
- 新增 src/services/task/request_state.py 定义 Protocol 与实现
- handler/executor/mixin 层改用 request_state 参数传递
- error_handler/state_transition 通过 request_state 判断整流状态
- 新增 request_state 单元测试与 chat/cli 请求体隔离测试
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from src.services.task.request_state import MutableRequestBodyState
|
|
|
|
|
|
def test_mutable_request_body_state_keeps_original_and_attempts_isolated() -> None:
|
|
original = {
|
|
"model": "gpt-5",
|
|
"input": [{"role": "user", "content": [{"type": "input_text", "text": "hello"}]}],
|
|
}
|
|
|
|
state = MutableRequestBodyState(original)
|
|
|
|
first_attempt = state.build_attempt_body()
|
|
first_attempt["input"][0]["content"][0]["text"] = "attempt-1"
|
|
|
|
assert original["input"][0]["content"][0]["text"] == "hello"
|
|
assert state.current_body["input"][0]["content"][0]["text"] == "hello"
|
|
|
|
rectified = state.build_attempt_body()
|
|
rectified["input"][0]["content"][0]["text"] = "rectified"
|
|
state.mark_rectified(rectified, stage=1)
|
|
|
|
second_attempt = state.build_attempt_body()
|
|
second_attempt["input"][0]["content"][0]["text"] = "attempt-2"
|
|
|
|
assert state.is_rectified() is True
|
|
assert state.rectify_stage() == 1
|
|
assert state.current_body["input"][0]["content"][0]["text"] == "rectified"
|
|
assert original["input"][0]["content"][0]["text"] == "hello"
|
|
assert state.consume_rectified_this_turn() is True
|
|
assert state.consume_rectified_this_turn() is False
|