Skip to content

Commit 3b91527

Browse files
committed
improvement(kb-search): mark sourceUrl nullable and cover non-null happy path in tests
1 parent c291a6d commit 3b91527

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

apps/sim/app/api/knowledge/search/route.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,10 @@ describe('Knowledge Search API Route', () => {
999999

10001000
mockGenerateSearchEmbedding.mockResolvedValue([0.1, 0.2, 0.3])
10011001
mockGetDocumentMetadataByIds.mockResolvedValue({
1002-
'doc-active': { filename: 'Active Document.pdf', sourceUrl: null },
1002+
'doc-active': {
1003+
filename: 'Active Document.pdf',
1004+
sourceUrl: 'https://example.atlassian.net/wiki/spaces/DOCS/pages/12345',
1005+
},
10031006
})
10041007

10051008
const mockTagDefs = {
@@ -1023,6 +1026,9 @@ describe('Knowledge Search API Route', () => {
10231026
expect(data.data.results).toHaveLength(1)
10241027
expect(data.data.results[0].documentId).toBe('doc-active')
10251028
expect(data.data.results[0].documentName).toBe('Active Document.pdf')
1029+
expect(data.data.results[0].sourceUrl).toBe(
1030+
'https://example.atlassian.net/wiki/spaces/DOCS/pages/12345'
1031+
)
10261032
})
10271033

10281034
it('should exclude results from deleted documents in tag search', async () => {

apps/sim/app/api/v1/knowledge/search/route.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,42 @@ describe('v1 knowledge search route — per-KB embedding model', () => {
127127
expect(mockGenerateSearchEmbedding).not.toHaveBeenCalled()
128128
})
129129

130+
it('surfaces sourceUrl from document metadata in search results', async () => {
131+
mockCheckKnowledgeBaseAccess.mockResolvedValueOnce({
132+
hasAccess: true,
133+
knowledgeBase: baseKb('kb-confluence', 'text-embedding-3-small'),
134+
})
135+
mockHandleVectorOnlySearch.mockResolvedValue([
136+
{
137+
documentId: 'doc-confluence',
138+
knowledgeBaseId: 'kb-confluence',
139+
content: 'page content',
140+
chunkIndex: 0,
141+
distance: 0.1,
142+
},
143+
])
144+
mockGetDocumentMetadataByIds.mockResolvedValue({
145+
'doc-confluence': {
146+
filename: 'Runbook.md',
147+
sourceUrl: 'https://example.atlassian.net/wiki/spaces/DOCS/pages/12345',
148+
},
149+
})
150+
151+
const req = createMockRequest('POST', {
152+
workspaceId: 'ws-1',
153+
knowledgeBaseIds: 'kb-confluence',
154+
query: 'runbook',
155+
})
156+
const res = await POST(req)
157+
const body = await res.json()
158+
159+
expect(res.status).toBe(200)
160+
expect(body.data.results[0].sourceUrl).toBe(
161+
'https://example.atlassian.net/wiki/spaces/DOCS/pages/12345'
162+
)
163+
expect(body.data.results[0].documentName).toBe('Runbook.md')
164+
})
165+
130166
it('allows tag-only search across mixed embedding models', async () => {
131167
mockHandleTagOnlySearch.mockResolvedValue([])
132168
mockCheckKnowledgeBaseAccess.mockResolvedValueOnce({

apps/sim/tools/knowledge/search.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export const knowledgeSearchTool: ToolConfig<any, KnowledgeSearchResponse> = {
179179
documentName: { type: 'string', description: 'Document name' },
180180
sourceUrl: {
181181
type: 'string',
182+
nullable: true,
182183
description:
183184
'URL to the original source document (e.g., Confluence page, Google Doc, Notion page). Null for documents without an external source.',
184185
},

apps/sim/tools/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface OutputProperty {
4646
type: OutputType
4747
description?: string
4848
optional?: boolean
49+
nullable?: boolean
4950
properties?: Record<string, OutputProperty>
5051
items?: {
5152
type: OutputType

0 commit comments

Comments
 (0)