Add web search and page retrieval to Toolbox

This commit is contained in:
Mark Gregory
2026-11-16 15:14:10 +00:00
parent 32c4b9f91c
commit 49140e0863
8 changed files with 246 additions and 20 deletions
+10
View File
@@ -96,6 +96,16 @@ class Handler(BaseHTTPRequestHandler):
self.reply(200, envelope, headers=headers)
def do_GET(self):
if self.path == '/search?q=tides+%26+moon&format=json' or self.path == '/search?q=tides%20%26%20moon&format=json':
page = f'http://127.0.0.1:{self.server.server_port}/article'
self.reply(200, {'results': [
{'url': page, 'title': '<b>Moon and tides</b>', 'content': 'A fixture &amp; summary'},
{'url': 'file:///etc/hosts', 'title': 'Invalid'},
{'url': page, 'title': 'Duplicate'}]})
return
if self.path == '/article':
self.reply(200, b'<h1>Moon and tides</h1><script>ignored()</script><p>Test passage.</p>', 'text/html')
return
if self.path == '/compatible/v1/models':
if self.headers.get('Authorization') != 'Bearer fixture-token':
self.reply(401)
+17
View File
@@ -554,3 +554,20 @@ final class WorkspaceLibraryTests: XCTestCase {
XCTAssertNoThrow(try WebClipCapture.url("https://example.com"))
}
}
final class WebToolsTests: XCTestCase {
func testSearchAndRetrieveKeepSourceURLs() async throws {
guard let endpoint = ProcessInfo.processInfo.environment["AISTUDIO_TEST_WEB_URL"] else {
throw XCTSkip("Run Scripts/test.sh to configure the web fixture.")
}
let results = try await WebSearch.results(endpoint: endpoint, query: "tides & moon")
XCTAssertEqual(results.count, 1)
let result = try XCTUnwrap(results.first)
XCTAssertEqual(result.title, "Moon and tides")
XCTAssertEqual(result.snippet, "A fixture & summary")
let page = try await WebClipCapture.page(from: result.url.absoluteString)
XCTAssertEqual(page.url, result.url)
XCTAssertEqual(page.text, "Moon and tides\nTest passage.")
XCTAssertTrue(page.reference.contains(result.url.absoluteString))
}
}