Skip to content

Commit 985f62d

Browse files
committed
fix(search-mcp): never take a Jira user showing another address as the person
1 parent 981c254 commit 985f62d

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎apps/sim/lib/sim-search/live/atlassian.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,27 @@ describe('Confluence plain search ranking', () => {
338338
expect(own.nextCursor).toBe('page-2')
339339
})
340340
})
341+
342+
describe('Jira person filter', () => {
343+
const users = '/ex/jira/cloud/rest/api/3/user/search'
344+
const search = (api: NativeClient) =>
345+
searchAtlassian(api, 'jira', { query: '', limit: 20, scopes: [], involving: 'jan@acme.com' })
346+
347+
it('never takes a prefix match showing another address as the person', async () => {
348+
const api = client({ [users]: [{ accountId: 'other-id', emailAddress: 'jan@acme.com.au' }] })
349+
await expect(search(api)).rejects.toThrow('No single Jira user')
350+
expect(api.json).not.toHaveBeenCalledWith(
351+
'/ex/jira/cloud/rest/api/3/search/jql',
352+
expect.anything()
353+
)
354+
})
355+
it('scopes issues to the one user whose address Jira hides', async () => {
356+
const api = client({
357+
[users]: [{ accountId: 'jan-id' }],
358+
'/ex/jira/cloud/rest/api/3/search/jql': { issues: [] },
359+
})
360+
await search(api)
361+
const [, options] = api.json.mock.calls.find(([path]) => path.endsWith('/search/jql')) ?? []
362+
expect(options?.body?.jql).toBe('(assignee = "jan-id" OR reporter = "jan-id")')
363+
})
364+
})

‎apps/sim/lib/sim-search/live/atlassian.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ interface SitePage {
144144

145145
/**
146146
* The account ID of the one user a site finds for an email, or undefined. Jira hides most email
147-
* addresses, so a lone match for an email query is that person. Account IDs span sites, so a
147+
* addresses, so a lone match with a hidden address is taken as that person. Account IDs span sites, so a
148148
* person found on any searched site applies to all of them.
149149
*/
150150
async function jiraAccountId(
@@ -159,7 +159,12 @@ async function jiraAccountId(
159159
})
160160
)
161161
const exact = found.filter((row) => string(row.emailAddress).toLowerCase() === email)
162-
const users = exact.length ? exact : found
162+
/** Search also matches prefixes, so a user showing a different address is never this person. */
163+
const users = exact.length
164+
? exact
165+
: found.length === 1 && !string(found[0]?.emailAddress)
166+
? found
167+
: []
163168
const accountId = string(users[0]?.accountId)
164169
return users.length === 1 && /^[\w:-]+$/.test(accountId) ? accountId : undefined
165170
}

0 commit comments

Comments
 (0)