22import { copilotChats , member , workspace } from '@sim/db/schema'
33import { queueTableRows , resetDbChainMock } from '@sim/testing'
44import { authBanMock , authBanMockFns } from '@sim/testing/mocks/auth-ban.mock'
5+ import { featureFlagsMock , featureFlagsMockFns } from '@sim/testing/mocks/feature-flags.mock'
56import {
67 permissionGroupsResolveMock ,
78 permissionGroupsResolveMockFns ,
@@ -21,6 +22,7 @@ vi.mock('@/lib/permission-groups/capability-assertions', async (importOriginal)
2122 ...( await importOriginal < typeof import ( '@/lib/permission-groups/capability-assertions' ) > ( ) ) ,
2223 assertWorkspaceCapability : mocks . capability ,
2324} ) )
25+ vi . mock ( '@/lib/core/config/feature-flags' , ( ) => featureFlagsMock )
2426const input = { chatId : 'chat-1' }
2527function principal ( ) {
2628 return createTrustedOrganizationCopilotPrincipal (
@@ -37,6 +39,7 @@ function queueChat(mode = 'plan', membership = true) {
3739describe ( 'private memory scope' , ( ) => {
3840 beforeEach ( ( ) => {
3941 resetDbChainMock ( )
42+ featureFlagsMockFns . mockIsFeatureEnabled . mockResolvedValue ( true )
4043 authBanMockFns . mockGetActivelyBannedUserIds . mockResolvedValue ( [ ] )
4144 permissionGroupsResolveMockFns . mockGetUserPermissionConfigForOrganization . mockResolvedValue (
4245 null
@@ -47,11 +50,33 @@ describe('private memory scope', () => {
4750 it . each ( [ 'plan' , 'agent' ] ) ( 'resolves the current %s chat owner' , async ( mode ) => {
4851 queueChat ( mode )
4952 expect ( await readMemoryScope . execute ( { principal : principal ( ) , input } ) ) . toEqual ( {
53+ enabled : true ,
5054 userId : 'actor' ,
5155 organizationId : 'org-1' ,
5256 workspaceId : null ,
5357 } )
5458 } )
59+ it ( 'reports Graphiti disabled independently of the chat mode and preserves its graph binding' , async ( ) => {
60+ featureFlagsMockFns . mockIsFeatureEnabled . mockResolvedValue ( false )
61+ queueTableRows ( copilotChats , [
62+ {
63+ userId : 'actor' ,
64+ organizationId : 'org-1' ,
65+ workspaceId : null ,
66+ type : 'mothership' ,
67+ mode : 'plan' ,
68+ memorySpaceId : 'saved-graph' ,
69+ } ,
70+ ] )
71+ queueTableRows ( member , [ { role : 'member' } ] )
72+ expect ( await readMemoryScope . execute ( { principal : principal ( ) , input } ) ) . toEqual ( {
73+ enabled : false ,
74+ userId : 'actor' ,
75+ organizationId : 'org-1' ,
76+ workspaceId : null ,
77+ spaceId : 'saved-graph' ,
78+ } )
79+ } )
5580 it . each ( [ 'user' , 'organization' , 'chat' , 'audience' , 'expired' ] as const ) (
5681 'rejects forged %s' ,
5782 async ( field ) => {
@@ -105,6 +130,7 @@ describe('private memory scope', () => {
105130 )
106131 queueWorkspace ( )
107132 expect ( await readMemoryScope . execute ( { principal : caller , input } ) ) . toEqual ( {
133+ enabled : true ,
108134 userId : 'actor' ,
109135 organizationId : 'canonical-org' ,
110136 workspaceId : 'workspace' ,
0 commit comments