-
Notifications
You must be signed in to change notification settings - Fork 20
feat(world-model): cross-org relationship_types + catalog discovery #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
packages/owletto-backend/src/tools/__tests__/search-cross-org.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /** | ||
| * Search tool surfaces public-catalog entities so tenant agents can discover | ||
| * canonical entities (HMRC, banks, currencies) without knowing their IDs | ||
| * upfront. Caller's-org entities still come back; public ones are added when | ||
| * the include_public_catalogs flag is on (default). | ||
| */ | ||
|
|
||
| import { beforeEach, describe, expect, it } from 'vitest'; | ||
| import { cleanupTestDatabase } from '../../__tests__/setup/test-db'; | ||
| import { | ||
| addUserToOrganization, | ||
| createTestEntity, | ||
| createTestOrganization, | ||
| createTestUser, | ||
| } from '../../__tests__/setup/test-fixtures'; | ||
| import { search } from '../search'; | ||
|
|
||
| describe('search cross-org public catalog discovery', () => { | ||
| beforeEach(async () => { | ||
| await cleanupTestDatabase(); | ||
| }); | ||
|
|
||
| it('returns matching entities from public-catalog orgs alongside tenant hits', async () => { | ||
| const tenant = await createTestOrganization({ name: 'Tenant Search' }); | ||
| const publicCatalog = await createTestOrganization({ | ||
| name: 'Public Catalog Search', | ||
| visibility: 'public', | ||
| }); | ||
| const user = await createTestUser(); | ||
| await addUserToOrganization(user.id, tenant.id, 'owner'); | ||
|
|
||
| const tenantEntity = await createTestEntity({ | ||
| name: 'Apple Local', | ||
| entity_type: 'brand', | ||
| organization_id: tenant.id, | ||
| }); | ||
| const publicEntity = await createTestEntity({ | ||
| name: 'Apple Inc', | ||
| entity_type: 'brand', | ||
| organization_id: publicCatalog.id, | ||
| }); | ||
|
|
||
| const result = await search( | ||
| { query: 'Apple', fuzzy: true, include_content: false }, | ||
| {} as Parameters<typeof search>[1], | ||
| { organizationId: tenant.id, userId: user.id } as Parameters<typeof search>[2] | ||
| ); | ||
|
|
||
| const ids = result.entities.map((e: { id: number }) => e.id); | ||
| expect(ids).toContain(tenantEntity.id); | ||
| expect(ids).toContain(publicEntity.id); | ||
| }); | ||
|
|
||
| it('omits public-catalog hits when include_public_catalogs=false', async () => { | ||
| const tenant = await createTestOrganization({ name: 'Tenant Local-Only' }); | ||
| const publicCatalog = await createTestOrganization({ | ||
| name: 'Public Catalog Local-Only', | ||
| visibility: 'public', | ||
| }); | ||
| const user = await createTestUser(); | ||
| await addUserToOrganization(user.id, tenant.id, 'owner'); | ||
|
|
||
| await createTestEntity({ | ||
| name: 'Local Apple', | ||
| entity_type: 'brand', | ||
| organization_id: tenant.id, | ||
| }); | ||
| const publicEntity = await createTestEntity({ | ||
| name: 'Public Apple', | ||
| entity_type: 'brand', | ||
| organization_id: publicCatalog.id, | ||
| }); | ||
|
|
||
| const result = await search( | ||
| { | ||
| query: 'Apple', | ||
| fuzzy: true, | ||
| include_content: false, | ||
| include_public_catalogs: false, | ||
| }, | ||
| {} as Parameters<typeof search>[1], | ||
| { organizationId: tenant.id, userId: user.id } as Parameters<typeof search>[2] | ||
| ); | ||
|
|
||
| const ids = result.entities.map((e: { id: number }) => e.id); | ||
| expect(ids).not.toContain(publicEntity.id); | ||
| }); | ||
|
|
||
| it('does not surface entities from private orgs the caller is not in', async () => { | ||
| const tenant = await createTestOrganization({ name: 'Tenant No-Snoop Search' }); | ||
| const otherPrivate = await createTestOrganization({ | ||
| name: 'Some Other Private', | ||
| visibility: 'private', | ||
| }); | ||
| const user = await createTestUser(); | ||
| await addUserToOrganization(user.id, tenant.id, 'owner'); | ||
|
|
||
| const privateEntity = await createTestEntity({ | ||
| name: 'Hidden Apple', | ||
| entity_type: 'brand', | ||
| organization_id: otherPrivate.id, | ||
| }); | ||
|
|
||
| const result = await search( | ||
| { query: 'Apple', fuzzy: true, include_content: false, include_public_catalogs: true }, | ||
| {} as Parameters<typeof search>[1], | ||
| { organizationId: tenant.id, userId: user.id } as Parameters<typeof search>[2] | ||
| ); | ||
|
|
||
| const ids = result.entities.map((e: { id: number }) => e.id); | ||
| expect(ids).not.toContain(privateEntity.id); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expanding the search scope here to all
visibility='public'entities means a public entity can become the primary hit, after whichformatEntityResultcallsfetchConnectionsForEntity(defaultinclude_connections=true) and returnsc.configwithout scoping by caller org. In any environment where multiple tenants attach feeds to the same canonical public entity, this allows one tenant’ssearchcall to read other tenants’ connection metadata/config for that entity. Please restrict connection hydration toctx.organizationId(or skip it for non-caller-org entities) when public results are enabled.Useful? React with 👍 / 👎.