Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions fastinsight/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,13 @@ def cleaned_text(self) -> str:


def _sender_id(sender: Dict[str, Any]) -> str:
sender_id = str(sender.get("id") or sender.get("sender_id") or "").strip()
if sender_id:
return sender_id
nested = sender.get("sender_id")
if isinstance(nested, dict):
return str(nested.get("open_id") or nested.get("user_id") or "").strip()
for value in (sender.get("id"), sender.get("sender_id")):
if isinstance(value, str) and value.strip():
return value.strip()
if isinstance(value, dict):
nested = value.get("open_id") or value.get("user_id")
if isinstance(nested, str) and nested.strip():
return nested.strip()
return ""


Expand Down
10 changes: 7 additions & 3 deletions scripts/auto_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ def _text(value):


def _verification_query(paper, title):
"""Combine identifiers with the best available title or content search query."""
"""Keep supplied locator evidence while adding the best search text."""
search_query = _text(paper.get("search_query"))
pieces = [search_query or _text(title)]
url = _text(paper.get("url"))
search_text = search_query or _text(title)
pieces = [url]
if search_text and search_text != url:
pieces.append(search_text)
doi = _text(paper.get("doi"))
arxiv_id = _text(paper.get("arxiv_id"))
if doi:
Expand Down Expand Up @@ -178,7 +182,7 @@ def enrich_paper(paper):
search_query = _text(paper.get("search_query"))
content_query = _text(paper.get("text"))[:500]
paper = _normalize_paper(paper)
query = search_query or source_title or content_query
query = search_query or source_title or content_query or _text(paper.get("url"))
if not query:
return paper
with tempfile.TemporaryDirectory(prefix="fastinsight-verify-") as temp_dir:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@


class ParseTests(unittest.TestCase):
def test_nested_sender_id_is_normalized_without_dict_repr(self) -> None:
parsed = parse_event(
{
"event": {
"sender": {"sender_id": {"open_id": "ou_nested", "user_id": "u_nested"}},
"message": {"content": '{"text":"hello"}'},
}
}
)
self.assertEqual(parsed.sender_id, "ou_nested")
self.assertNotIn("{", parsed.sender_id)

def test_command_with_mention(self) -> None:
parsed = parse_feishu_message(
{
Expand Down
15 changes: 15 additions & 0 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ def test_search_query_is_prioritized_for_verification(self) -> None:
)
self.assertEqual(query, "FirmAgent firmware fuzzing")

def test_verification_query_keeps_existing_url(self) -> None:
query = _verification_query(
{"url": "https://arxiv.org/abs/1706.03762", "title": "A description"},
"A description",
)
self.assertEqual(query, "https://arxiv.org/abs/1706.03762 A description")

def test_url_only_paper_reaches_verifier(self) -> None:
with patch("scripts.auto_pipeline._run_json", return_value=({}, 0)) as run:
from scripts.auto_pipeline import enrich_paper

enrich_paper({"url": "https://example.test/paper"})
command = run.call_args.args[0]
self.assertEqual(command[command.index("--query") + 1], "https://example.test/paper")


if __name__ == "__main__":
unittest.main()
Loading