-
Notifications
You must be signed in to change notification settings - Fork 138
feat: complete DAL scope helper migration and error handling infrastructure #2701
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
22 commits
Select commit
Hold shift + click to select a range
e2a0cdf
[US-001] Generalize scope helpers for runtime tables and add barrel e…
amikofalvy ac98033
[US-002] Fix unscoped runtime DAL functions (security)
amikofalvy 8eacee2
[US-003] Add PG retry utility and fix runtime-tasks-scoping test type…
amikofalvy 15c7ebb
[US-004] Fix ledgerArtifacts.ts crash bug and replace ad-hoc FK viola…
amikofalvy 5fe6273
[US-005] Extract Drizzle queries from auth.ts and add DAL boundary li…
amikofalvy 28bf794
[US-006] Migrate 9 simple manage DAL files to scope helpers
amikofalvy ec27cb1
[US-007] Migrate agents, credentialReferences, dataComponents, artifa…
amikofalvy e8c9117
[US-008] Migrate skills, functionTools, projects, projectLifecycle to…
amikofalvy 46af230
[US-009] Migrate subAgentRelations.ts to scope helpers
amikofalvy 05b2c54
[US-010] Migrate evalConfig.ts to scope helpers
amikofalvy 7a0bb28
[US-011] Migrate subAgentTeamAgentRelations and agentFull to scope he…
amikofalvy 8f810f8
[US-012] Migrate 10 runtime DAL files to scope helpers
amikofalvy a190502
[US-013] Migrate 5 runtime DAL files with mixed params to scope helpers
amikofalvy 30fd2cc
style: auto-format with biome
github-actions[bot] 3a62977
fix: correct scope level for subAgents and subAgentArtifactComponents…
amikofalvy e48f7f9
refactor: tighten types in fetchComponentRelationships to remove as-a…
amikofalvy 24ac971
refactor: extract repeated scope objects into reusable variables
amikofalvy dd27b55
fix: address PR review feedback — inline error checks and lint script
amikofalvy 16413b6
fix: address remaining PR review comments (1-5)
amikofalvy 6c11c7e
chore: add changeset for DAL scope helper migration
amikofalvy 0e94d78
chore: soften changeset message
amikofalvy 07a69b0
docs: add dal-boundary to pnpm check description in AGENTS.md
amikofalvy 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@inkeep/agents-core": patch | ||
| --- | ||
|
|
||
| Add defense-in-depth tenant scoping to runtime DAL functions and migrate all DAL files to type-safe scope helpers |
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
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
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
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
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
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
92 changes: 92 additions & 0 deletions
92
packages/agents-core/src/__tests__/data-access/scoping/runtime-contextCache-scoping.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,92 @@ | ||
| import { beforeEach, describe, expect, it } from 'vitest'; | ||
| import { getCacheEntry, setCacheEntry } from '../../../data-access/runtime/contextCache'; | ||
| import type { AgentsRunDatabaseClient } from '../../../db/runtime/runtime-client'; | ||
| import { contextCache, conversations } from '../../../db/runtime/runtime-schema'; | ||
| import { generateId } from '../../../utils/conversations'; | ||
| import { testRunDbClient } from '../../setup'; | ||
|
|
||
| describe('runtime contextCache scoping isolation', () => { | ||
| let db: AgentsRunDatabaseClient; | ||
| const tenantA = 'tenant-a'; | ||
| const tenantB = 'tenant-b'; | ||
| const projectA = 'project-a'; | ||
| const projectB = 'project-b'; | ||
| const conversationId = 'conv-1'; | ||
| const contextConfigId = 'config-1'; | ||
| const contextVariableKey = 'var-key'; | ||
|
|
||
| beforeEach(async () => { | ||
| db = testRunDbClient; | ||
| await db.delete(contextCache); | ||
| await db.delete(conversations); | ||
|
|
||
| await db.insert(conversations).values({ | ||
| id: conversationId, | ||
| tenantId: tenantA, | ||
| projectId: projectA, | ||
| activeSubAgentId: 'sub-1', | ||
| }); | ||
| }); | ||
|
|
||
| it('getCacheEntry should not return a cache entry belonging to a different tenant', async () => { | ||
| await setCacheEntry(db)({ | ||
| id: generateId(), | ||
| tenantId: tenantA, | ||
| projectId: projectA, | ||
| conversationId, | ||
| contextConfigId, | ||
| contextVariableKey, | ||
| ref: { type: 'branch', name: 'main', hash: 'abc' }, | ||
| value: { data: 'test' }, | ||
| fetchedAt: new Date().toISOString(), | ||
| }); | ||
|
|
||
| const wrongTenant = await getCacheEntry(db)({ | ||
| conversationId, | ||
| contextConfigId, | ||
| contextVariableKey, | ||
| scopes: { tenantId: tenantB, projectId: projectA }, | ||
| }); | ||
| expect(wrongTenant).toBeNull(); | ||
|
|
||
| const correctTenant = await getCacheEntry(db)({ | ||
| conversationId, | ||
| contextConfigId, | ||
| contextVariableKey, | ||
| scopes: { tenantId: tenantA, projectId: projectA }, | ||
| }); | ||
| expect(correctTenant).not.toBeNull(); | ||
| expect(correctTenant?.conversationId).toBe(conversationId); | ||
| }); | ||
|
|
||
| it('getCacheEntry should not return a cache entry belonging to a different project', async () => { | ||
| await setCacheEntry(db)({ | ||
| id: generateId(), | ||
| tenantId: tenantA, | ||
| projectId: projectA, | ||
| conversationId, | ||
| contextConfigId, | ||
| contextVariableKey, | ||
| ref: { type: 'branch', name: 'main', hash: 'abc' }, | ||
| value: { data: 'test' }, | ||
| fetchedAt: new Date().toISOString(), | ||
| }); | ||
|
|
||
| const wrongProject = await getCacheEntry(db)({ | ||
| conversationId, | ||
| contextConfigId, | ||
| contextVariableKey, | ||
| scopes: { tenantId: tenantA, projectId: projectB }, | ||
| }); | ||
| expect(wrongProject).toBeNull(); | ||
|
|
||
| const correctProject = await getCacheEntry(db)({ | ||
| conversationId, | ||
| contextConfigId, | ||
| contextVariableKey, | ||
| scopes: { tenantId: tenantA, projectId: projectA }, | ||
| }); | ||
| expect(correctProject).not.toBeNull(); | ||
| expect(correctProject?.conversationId).toBe(conversationId); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
This test only verifies cross-tenant isolation. Unlike the tasks scoping test which has a dedicated cross-project case, there's no test that inserts a cache entry for
projectAand queries withprojectB. Add one to verify project-level isolation.