Removes the "Daybook" name from everything user- and agent-facing, since no agents are configured yet and this is the cheap moment to do it. - UI brand, docs, README, CLAUDE.md -> AgentFeed. - Ingest env vars DAYBOOK_URL/TOKEN/SOURCE/DATA_DIR/BIND_ADDR/HOST_DATA_DIR/ KEY_PROVISIONING_API -> AGENTFEED_* (token *values* unchanged). - Skill: skills/daybook-posting -> skills/agentfeed-posting, daybook_post.py -> agentfeed_post.py (+ scripts/ wrapper and its test). - static/daybook.css -> static/agentfeed.css; localStorage daybook.* -> agentfeed.*; templatetag daybook_extras -> agentfeed_extras; multipart boundaries; json/csv viewer element ids; daybook_exception_handler -> agentfeed_exception_handler; compose service/container -> agentfeed. - Key-provisioning API now OFF by default (independent of DEBUG); enable with AGENTFEED_KEY_PROVISIONING_API=1 on test installs only. - Posting helper now points at Settings -> API Keys. Deferred on purpose (a later, separate step): the Django package `daybook_project`, the `/opt/daybook` install path, and the Forgejo repo name. The sibling AGENT_DAYBOOK__LLM_TEST name is intentionally untouched. Full suite: 129 passing; live server verified serving under the new name. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
117 lines
4.1 KiB
Python
117 lines
4.1 KiB
Python
import importlib.util
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
SCRIPT_PATH = (
|
|
Path(__file__).resolve().parents[2]
|
|
/ "skills"
|
|
/ "agentfeed-posting"
|
|
/ "scripts"
|
|
/ "agentfeed_post.py"
|
|
)
|
|
|
|
|
|
def _load_module():
|
|
spec = importlib.util.spec_from_file_location("agentfeed_post", SCRIPT_PATH)
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
agentfeed_post = _load_module()
|
|
|
|
|
|
class SniffTextKindTestCase(unittest.TestCase):
|
|
def test_markdown_suffixes(self):
|
|
for suffix in (".md", ".markdown", ".txt"):
|
|
self.assertEqual(agentfeed_post.sniff_text_kind(suffix, "anything"), "markdown")
|
|
|
|
def test_json_suffix(self):
|
|
self.assertEqual(agentfeed_post.sniff_text_kind(".json", '{"a": 1}'), "json")
|
|
|
|
def test_csv_suffix(self):
|
|
self.assertEqual(agentfeed_post.sniff_text_kind(".csv", "a,b\n1,2"), "csv")
|
|
|
|
def test_html_full_sniffed_from_content(self):
|
|
self.assertEqual(
|
|
agentfeed_post.sniff_text_kind(".html", "<!doctype html><html></html>"), "html_full"
|
|
)
|
|
|
|
def test_deck_sniffed_from_content(self):
|
|
self.assertEqual(agentfeed_post.sniff_text_kind(".html", "<section>slide</section>"), "deck")
|
|
|
|
def test_html_fragment_is_the_fallback(self):
|
|
self.assertEqual(agentfeed_post.sniff_text_kind(".html", "<p>hi</p>"), "html_fragment")
|
|
|
|
|
|
class ValidatePayloadTestCase(unittest.TestCase):
|
|
def test_valid_json_passes(self):
|
|
agentfeed_post.validate_payload({"kind": "json", "content": '{"a": 1}'}, None) # no raise
|
|
|
|
def test_invalid_json_raises(self):
|
|
with self.assertRaises(ValueError):
|
|
agentfeed_post.validate_payload({"kind": "json", "content": "{not json"}, None)
|
|
|
|
def test_deck_without_section_raises(self):
|
|
with self.assertRaises(ValueError):
|
|
agentfeed_post.validate_payload({"kind": "deck", "content": "<h1>no slides</h1>"}, None)
|
|
|
|
def test_html_fragment_with_nested_html_raises(self):
|
|
with self.assertRaises(ValueError):
|
|
agentfeed_post.validate_payload(
|
|
{"kind": "html_fragment", "content": "<html><body>x</body></html>"}, None
|
|
)
|
|
|
|
def test_html_full_without_html_tag_raises(self):
|
|
with self.assertRaises(ValueError):
|
|
agentfeed_post.validate_payload({"kind": "html_full", "content": "<p>x</p>"}, None)
|
|
|
|
def test_blank_markdown_raises(self):
|
|
with self.assertRaises(ValueError):
|
|
agentfeed_post.validate_payload({"kind": "markdown", "content": " "}, None)
|
|
|
|
def test_csv_has_no_shape_check(self):
|
|
agentfeed_post.validate_payload({"kind": "csv", "content": "anything at all"}, None) # no raise
|
|
|
|
def test_upload_path_skips_all_checks(self):
|
|
agentfeed_post.validate_payload({"upload_path": Path("whatever.png")}, None) # no raise
|
|
|
|
|
|
class ResolveAutoPathTestCase(unittest.TestCase):
|
|
def _args(self, path):
|
|
class Args:
|
|
pass
|
|
|
|
args = Args()
|
|
args.path = str(path)
|
|
args.as_markdown = False
|
|
args.title = None
|
|
return args
|
|
|
|
def test_json_file_infers_json_kind(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / "data.json"
|
|
path.write_text('{"a": 1}', encoding="utf-8")
|
|
args = agentfeed_post.resolve_auto_path(self._args(path))
|
|
self.assertEqual(args.kind, "json")
|
|
self.assertEqual(args.content_file, str(path))
|
|
|
|
def test_csv_file_infers_csv_kind(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / "data.csv"
|
|
path.write_text("a,b\n1,2", encoding="utf-8")
|
|
args = agentfeed_post.resolve_auto_path(self._args(path))
|
|
self.assertEqual(args.kind, "csv")
|
|
|
|
def test_image_file_becomes_multipart_upload(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / "chart.png"
|
|
path.write_bytes(b"\x89PNG\r\n")
|
|
args = agentfeed_post.resolve_auto_path(self._args(path))
|
|
self.assertIsNone(args.kind)
|
|
self.assertEqual(args.file, str(path))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|