fix: normalize escaped Work artifacts

This commit is contained in:
wuyang
2026-07-26 14:03:01 +08:00
parent f149379cf7
commit 44fe0b3dd7
2 changed files with 173 additions and 3 deletions
+26 -1
View File
@@ -7,7 +7,12 @@ from typing import Any
from agent_platform.auth import UserIdentity
from agent_platform.models import get_model_spec
from agent_platform.runtime.loop import AgentLoop, tool_event_details
from agent_platform.runtime.loop import (
AgentLoop,
is_substantive_execution,
normalize_write_file_content,
tool_event_details,
)
from agent_platform.runtime.tools import TOOL_METADATA
from agent_platform.store import RuntimeStore
@@ -20,6 +25,26 @@ def tool_call(call_id: str, name: str, arguments: dict[str, Any]) -> dict[str, A
}
def test_write_file_normalizes_double_escaped_code_layout() -> None:
escaped = r'import time\n\n# benchmark\ndef main():\n\tprint("keep\ninside")\n\nmain()\n'
assert normalize_write_file_content("benchmark.py", escaped) == (
'import time\n\n# benchmark\ndef main():\n\tprint("keep\\ninside")\n\nmain()\n'
)
def test_write_file_normalizes_double_escaped_plain_text() -> None:
assert normalize_write_file_content("report.md", r"# Report\n\nMeasured: 1.2 s\n") == (
"# Report\n\nMeasured: 1.2 s\n"
)
def test_read_only_shell_commands_do_not_satisfy_execution_evidence() -> None:
assert not is_substantive_execution("exec", {"command": "cat report.txt"})
assert not is_substantive_execution("exec", {"command": "sed -n '1,20p' script.py"})
assert is_substantive_execution("exec", {"command": "python3 script.py"})
assert is_substantive_execution("start_process", {"command": "python3 server.py"})
class ScriptedProvider:
def __init__(self, responses: list[dict[str, Any]]) -> None:
self.responses = responses