mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-07-09 17:08:29 +00:00
Add comprehensive file-level DOX documentation across the repo and update directory AGENTS.md indexes. Many new `*.py.dox.md` files were added under api, helpers, tools, plugins, extensions, webui, and other dirs to document endpoint purpose, ownership, runtime contracts, work guidance, and verification. Several AGENTS.md files were created or updated (agents profiles, api, docker, extensions, helpers, plugins, skills, webui components, etc.) to list child DOX files and clarify documentation/work guidance. Also add example and bundled profile DOX files (agent0, default, developer, hacker, researcher) and minor updates to helpers/dirty_json.py and its tests. These changes improve on-disk documentation coverage and establish the convention that each direct runtime file should have a matching `*.dox.md` describing its contracts and verification steps.
95 lines
2.5 KiB
Python
95 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
if str(PROJECT_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
from helpers.dirty_json import DirtyJson
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("payload", "expected"),
|
|
[
|
|
(
|
|
'{"tool_name":"x","tool_args":{}}',
|
|
{"tool_name": "x", "tool_args": {}},
|
|
),
|
|
("[1, 2, 3]", [1, 2, 3]),
|
|
],
|
|
)
|
|
def test_completed_true_when_root_is_explicitly_closed(payload, expected) -> None:
|
|
parser = DirtyJson()
|
|
|
|
assert parser.parse(payload) == expected
|
|
assert parser.completed is True
|
|
|
|
|
|
def test_completed_false_when_root_hits_eof_before_closing() -> None:
|
|
parser = DirtyJson()
|
|
|
|
assert parser.parse('{"tool_name":"x","tool_args":{}') == {
|
|
"tool_name": "x",
|
|
"tool_args": {},
|
|
}
|
|
assert parser.completed is False
|
|
|
|
|
|
def test_completed_remains_true_after_trailing_content() -> None:
|
|
parser = DirtyJson()
|
|
|
|
assert parser.feed('{"tool_name":"x","tool_args":{}}') == {
|
|
"tool_name": "x",
|
|
"tool_args": {},
|
|
}
|
|
assert parser.completed is True
|
|
|
|
assert parser.feed(" trailing noise") == {
|
|
"tool_name": "x",
|
|
"tool_args": {},
|
|
}
|
|
|
|
assert parser.completed is True
|
|
|
|
|
|
def test_value_keeps_unescaped_markdown_quotes_until_structural_delimiter() -> None:
|
|
payload = (
|
|
"{\n"
|
|
' "tool_name": "response",\n'
|
|
' "tool_args": {\n'
|
|
' "text": "The rule:\\n\\n> *"'
|
|
'Create a child AGENTS.md when a folder becomes a boundary."'
|
|
'*\\n\\nAdding `css/AGENTS.md` that says *"'
|
|
'this folder contains CSS"'
|
|
'* is duplication."\n'
|
|
" }\n"
|
|
"}"
|
|
)
|
|
|
|
parsed = DirtyJson.parse_string(payload)
|
|
|
|
assert parsed["tool_args"] == {
|
|
"text": (
|
|
"The rule:\n\n"
|
|
'> *"Create a child AGENTS.md when a folder becomes a boundary."*\n\n'
|
|
'Adding `css/AGENTS.md` that says *"this folder contains CSS"* is duplication.'
|
|
)
|
|
}
|
|
|
|
|
|
def test_value_keeps_unescaped_quotes_on_single_line() -> None:
|
|
parsed = DirtyJson.parse_string(
|
|
'{"text":"He said "hello" before closing","ok":true}'
|
|
)
|
|
|
|
assert parsed == {"text": 'He said "hello" before closing', "ok": True}
|
|
|
|
|
|
def test_value_can_still_end_before_quoted_key_when_comma_is_missing() -> None:
|
|
parsed = DirtyJson.parse_string('{"first":"one" "second":"two"}')
|
|
|
|
assert parsed == {"first": "one", "second": "two"}
|