Add site filters for manual connection selection (#328)
This commit is contained in:
@@ -138,6 +138,34 @@ describe('search routes', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns site matches for platform keywords in global search', async () => {
|
||||
const site = await db.insert(schema.sites).values({
|
||||
name: 'Direct Workspace',
|
||||
url: 'https://workspace.example.com',
|
||||
platform: 'codex',
|
||||
}).returning().get();
|
||||
|
||||
const response = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/search',
|
||||
payload: {
|
||||
query: 'codex',
|
||||
limit: 20,
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json()).toMatchObject({
|
||||
sites: [
|
||||
expect.objectContaining({
|
||||
id: site.id,
|
||||
name: 'Direct Workspace',
|
||||
url: 'https://workspace.example.com',
|
||||
}),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('includes oauth direct-account model availability in model search results', async () => {
|
||||
const site = await db.insert(schema.sites).values({
|
||||
name: 'codex site',
|
||||
|
||||
@@ -46,14 +46,13 @@ export async function searchRoutes(app: FastifyInstance) {
|
||||
const perCategory = Math.min(Math.ceil(limit / 6), 10);
|
||||
|
||||
// Search sites
|
||||
const sites = (await db.select().from(schema.sites)
|
||||
.where(like(schema.sites.name, q))
|
||||
.limit(perCategory).all())
|
||||
.concat(
|
||||
await db.select().from(schema.sites)
|
||||
.where(like(schema.sites.url, q))
|
||||
.limit(perCategory).all()
|
||||
);
|
||||
const sites = await db.select().from(schema.sites)
|
||||
.where(or(
|
||||
like(schema.sites.name, q),
|
||||
like(schema.sites.url, q),
|
||||
like(schema.sites.platform, q),
|
||||
))
|
||||
.limit(perCategory).all();
|
||||
// Deduplicate by id
|
||||
const uniqueSites = [...new Map(sites.map(s => [s.id, s])).values()].slice(0, perCategory);
|
||||
|
||||
@@ -63,6 +62,7 @@ export async function searchRoutes(app: FastifyInstance) {
|
||||
.where(or(
|
||||
like(schema.accounts.username, q),
|
||||
like(schema.sites.name, q),
|
||||
like(schema.sites.platform, q),
|
||||
))
|
||||
.limit(perCategory).all();
|
||||
const apiKeyLabelMatches = matchesApiKeyDisplayLabel(query);
|
||||
@@ -91,6 +91,7 @@ export async function searchRoutes(app: FastifyInstance) {
|
||||
like(schema.accountTokens.tokenGroup, q),
|
||||
like(schema.accounts.username, q),
|
||||
like(schema.sites.name, q),
|
||||
like(schema.sites.platform, q),
|
||||
))
|
||||
.orderBy(desc(schema.accountTokens.updatedAt))
|
||||
.limit(perCategory)
|
||||
|
||||
Reference in New Issue
Block a user