mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 01:16:18 -05:00
ai: wrolpi_mcp becomes a thin proxy over /api/ai
Every MCP tool is now one /api/ai call with minimal text rendering;
the formatting, link building, and truncation logic it used to carry
untested lives (tested) in modules/ai. Tool names are unchanged for
external clients; a source-scan test guards the names and that the
proxy only reaches /api/ai. New lean blueprint endpoints back the two
tools that had no equivalent: GET archives/{id} (detail + snapshot
history) and GET videos/{id}/comments (paged author lines). Paged
content is read up to the old 50k-char bound. get_inventory_items now
takes the inventory slug (inventories are config-only; the old
numeric-id endpoint no longer exists). This also brings wrolpi_mcp
into version control (venv/ is already gitignored).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
69d78ad95d
commit
9f22b09b0a
9 changed files with 692 additions and 0 deletions
|
|
@ -140,6 +140,47 @@ async def test_ai_get_archive_text(async_client, test_session, archive_factory):
|
|||
assert response.status_code == HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ai_get_archive(async_client, test_session, archive_factory):
|
||||
"""A single archive can be fetched with its history of snapshots."""
|
||||
archive_factory(domain='example.com', url='https://example.com/a', title='first', contents='one')
|
||||
archive = archive_factory(domain='example.com', url='https://example.com/a', title='second', contents='two')
|
||||
test_session.commit()
|
||||
|
||||
request, response = await async_client.get(f'/api/ai/archives/{archive.file_group_id}')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json['kind'] == 'archive'
|
||||
assert response.json['link'] == f'/archives/{archive.file_group_id}'
|
||||
# History holds the OTHER snapshots of the URL, not the archive itself.
|
||||
assert [i['title'] for i in response.json['history']] == ['first']
|
||||
|
||||
request, response = await async_client.get('/api/ai/archives/123456')
|
||||
assert response.status_code == HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ai_get_video_comments(async_client, test_session, video_factory):
|
||||
"""Video comments render as paged author lines."""
|
||||
info_json = dict(duration=5, comments=[
|
||||
dict(author='alice', text='great video'),
|
||||
dict(author='bob', text='thanks'),
|
||||
])
|
||||
video = video_factory(title='commented', with_info_json=info_json)
|
||||
test_session.commit()
|
||||
|
||||
request, response = await async_client.get(f'/api/ai/videos/{video.file_group_id}/comments')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert 'alice: great video' in response.json['content']
|
||||
assert 'bob: thanks' in response.json['content']
|
||||
|
||||
# No comments is an empty page, not an error.
|
||||
no_comments = video_factory(title='quiet')
|
||||
test_session.commit()
|
||||
request, response = await async_client.get(f'/api/ai/videos/{no_comments.file_group_id}/comments')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json['content'] == ''
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ai_search_docs(async_client, test_session, test_directory, example_epub, refresh_files):
|
||||
"""Docs can be searched and fetched with links."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue