mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-11-05 20:52:22 +01:00
Preserve preview harness, editor, email and task improvements
Snapshot current maintainer-preview application changes and regression fixtures for integration into lab. Excludes local runtime data, evaluation outputs and source backups. Focused Python regression selection: 140 passed; full suite not certified.
This commit is contained in:
@@ -36,6 +36,61 @@ class _FakeErrorResponse:
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('markup', [
|
||||
'<main><article><h2><a href="/one">First story</a></h2><p>3 points</p></article><article><h2><a href="/two">Second story</a></h2><p>900 points</p></article></main>',
|
||||
'<body><table><tr><td>1.</td><td><a href="/vote"><img src="up.png"></a></td><td><a href="/one">First story</a></td></tr><tr><td>3 points</td></tr><tr><td>2.</td><td><a href="/two">Second story</a></td></tr><tr><td>900 points</td></tr></table></body>',
|
||||
'<main><ol><li><a href="/one">First story</a> 3 points</li><li><a href="/two">Second story</a> 900 points</li></ol></main>',
|
||||
])
|
||||
def test_listing_links_preserve_destination_and_source_order(markup, tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(service_content, 'CONTENT_CACHE_DIR', tmp_path)
|
||||
monkeypatch.setattr(service_content, '_get_public_url', lambda *a, **k: _FakeResponse(markup))
|
||||
result = service_content.fetch_webpage_content('https://example.org/list')
|
||||
text = result['linked_content']
|
||||
assert '[First story](<https://example.org/one>)' in text
|
||||
assert '[Second story](<https://example.org/two>)' in text
|
||||
assert text.index('First story') < text.index('Second story')
|
||||
assert '\n' in text
|
||||
assert '](' not in result['content']
|
||||
assert result['page_entries'] == [
|
||||
{'title': 'First story', 'url': 'https://example.org/one'},
|
||||
{'title': 'Second story', 'url': 'https://example.org/two'},
|
||||
]
|
||||
|
||||
|
||||
def test_link_extraction_ignores_unsafe_schemes_and_escapes_labels():
|
||||
from bs4 import BeautifulSoup
|
||||
html = '<main><a href="javascript:alert(1)">Bad</a><a href="#part">Jump</a><a href="/a?q=1&b=2">A [label]</a></main>'
|
||||
text = service_content._linked_text(BeautifulSoup(html, 'html.parser'), 'https://example.org/')
|
||||
assert 'javascript:' not in text
|
||||
assert '[Jump]' not in text
|
||||
assert r'[A \[label\]](<https://example.org/a?q=1&b=2>)' in text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_web_fetch_delivers_linked_content_to_model(monkeypatch):
|
||||
from src.agent_tools.web_tools import WebFetchTool
|
||||
from src.search import content
|
||||
linked = '[First story](<https://example.org/one>)\n[Second story](<https://example.org/two>)'
|
||||
monkeypatch.setattr(content, 'fetch_webpage_content', lambda *a, **k: {
|
||||
'title': 'Listing', 'content': 'First story Second story', 'linked_content': linked,
|
||||
})
|
||||
result = await WebFetchTool().execute('{"url":"https://example.org/list"}', {})
|
||||
assert result['exit_code'] == 0
|
||||
assert linked in result['output']
|
||||
|
||||
|
||||
def test_simple_listing_is_rendered_with_links_without_reranking():
|
||||
from src.clean_agent_preview import page_listing_response
|
||||
entries = [{'title': 'Low points first', 'url': 'https://example.org/a'},
|
||||
{'title': 'High points second', 'url': 'https://example.org/b'}]
|
||||
text = page_listing_response(entries, 'top hackernews stories')
|
||||
assert '1. [Low points first](<https://example.org/a>)' in text
|
||||
assert '2. [High points second](<https://example.org/b>)' in text
|
||||
assert page_listing_response(entries, 'Summarize the articles') == ''
|
||||
assert page_listing_response(entries, 'top stories and email them to Jon') == ''
|
||||
assert page_listing_response(entries, 'top stories about science') == ''
|
||||
|
||||
|
||||
def test_single_article_inside_main_excludes_related_links_and_comment_form(tmp_path, monkeypatch):
|
||||
body = 'The measured storage comparison includes uncertainty and cost limitations. ' * 8
|
||||
html = f'<main><article><h1>Storage comparison</h1><p>{body}</p></article><section>Related posts: home battery storage tags</section><form>Leave a comment</form></main>'
|
||||
|
||||
Reference in New Issue
Block a user