2
0

Add FASP account search support (#34033)

This commit is contained in:
David Roetzel
2025-06-30 09:42:34 +02:00
committed by GitHub
parent 6d017dbf10
commit ac4b735c67
8 changed files with 130 additions and 3 deletions

View File

@@ -41,3 +41,15 @@ Fabricator(:follow_recommendation_fasp, from: :fasp_provider) do
def fasp.update_remote_capabilities = true
end
end
Fabricator(:account_search_fasp, from: :fasp_provider) do
confirmed true
capabilities [
{ id: 'account_search', version: '0.1', enabled: true },
]
after_build do |fasp|
# Prevent fabrication from attempting an HTTP call to the provider
def fasp.update_remote_capabilities = true
end
end

View File

@@ -118,6 +118,15 @@ RSpec.describe 'Search API' do
.to start_with('application/json')
end
end
context 'when `account_search` FASP is enabled', feature: :fasp do
it 'enqueues a retrieval job and adds a header to inform the client' do
get '/api/v2/search', headers: headers, params: params
expect(Fasp::AccountSearchWorker).to have_enqueued_sidekiq_job
expect(response.headers['Mastodon-Async-Refresh']).to be_present
end
end
end
end

View File

@@ -66,7 +66,7 @@ RSpec.describe SearchService do
allow(AccountSearchService).to receive(:new).and_return(service)
results = subject.call(query, nil, 10)
expect(service).to have_received(:call).with(query, nil, limit: 10, offset: 0, resolve: false, start_with_hashtag: false, use_searchable_text: true, following: false)
expect(service).to have_received(:call).with(query, nil, limit: 10, offset: 0, resolve: false, start_with_hashtag: false, use_searchable_text: true, following: false, query_fasp: nil)
expect(results).to eq empty_results.merge(accounts: [account])
end
end

View File

@@ -0,0 +1,50 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Fasp::AccountSearchWorker, feature: :fasp do
include ProviderRequestHelper
let(:provider) { Fabricate(:account_search_fasp) }
let(:account) { Fabricate(:account) }
let(:fetch_service) { instance_double(ActivityPub::FetchRemoteActorService, call: true) }
let!(:stubbed_request) do
path = '/account_search/v0/search?term=cats&limit=10'
stub_provider_request(provider,
method: :get,
path:,
response_body: [
'https://fedi.example.com/accounts/2',
'https://fedi.example.com/accounts/9',
])
end
before do
allow(ActivityPub::FetchRemoteActorService).to receive(:new).and_return(fetch_service)
end
it 'requests search results and fetches received account uris' do
described_class.new.perform('cats')
expect(stubbed_request).to have_been_made
expect(fetch_service).to have_received(:call).with('https://fedi.example.com/accounts/2')
expect(fetch_service).to have_received(:call).with('https://fedi.example.com/accounts/9')
end
it 'marks a running async refresh as finished' do
async_refresh = AsyncRefresh.create("fasp:account_search:#{Digest::MD5.base64digest('cats')}", count_results: true)
described_class.new.perform('cats')
expect(async_refresh.reload).to be_finished
end
it 'tracks the number of fetched accounts in the async refresh' do
async_refresh = AsyncRefresh.create("fasp:account_search:#{Digest::MD5.base64digest('cats')}", count_results: true)
described_class.new.perform('cats')
expect(async_refresh.reload.result_count).to eq 2
end
end