@@ -193,6 +193,73 @@ describe('knowledge workspace source provenance', () => {
193193 )
194194 } )
195195
196+ it ( 'preserves a tracked exact-empty manual upload as model-safe' , async ( ) => {
197+ mockGetBoundWorkspaceFileSecretProvenanceByMetadata . mockResolvedValue (
198+ new Map ( [ [ SOURCE_BINDING . id , { status : 'exact' , entries : [ ] } ] ] )
199+ )
200+
201+ await createSingleDocument (
202+ {
203+ filename : 'source.pdf' ,
204+ fileUrl : SOURCE_URL ,
205+ fileSize : 512 ,
206+ mimeType : 'application/pdf' ,
207+ } ,
208+ KNOWLEDGE_BASE_ID ,
209+ 'request-1' ,
210+ SOURCE_USER_ID
211+ )
212+
213+ expect ( findDocumentProvenanceWrite ( ) ) . toEqual (
214+ expect . objectContaining ( { status : 'exact' , entries : [ ] } )
215+ )
216+ } )
217+
218+ it ( 'uses the trusted mothership row context instead of the URL context label' , async ( ) => {
219+ const mothershipBinding = {
220+ ...SOURCE_BINDING ,
221+ id : 'mothership-file-1' ,
222+ context : 'mothership' ,
223+ }
224+ mockGetFileMetadataByKeys . mockImplementation ( async ( _keys : string [ ] , context : string ) =>
225+ context === 'mothership' ? [ mothershipBinding ] : [ ]
226+ )
227+ mockGetBoundWorkspaceFileSecretProvenanceByMetadata . mockResolvedValue (
228+ new Map ( [
229+ [
230+ mothershipBinding . id ,
231+ {
232+ status : 'exact' ,
233+ entries : [ { name : 'CHAT_SECRET' , encryptedValue : 'encrypted-chat-secret' } ] ,
234+ } ,
235+ ] ,
236+ ] )
237+ )
238+
239+ await createSingleDocument (
240+ {
241+ filename : 'source.pdf' ,
242+ fileUrl : SOURCE_URL ,
243+ fileSize : 512 ,
244+ mimeType : 'application/pdf' ,
245+ } ,
246+ KNOWLEDGE_BASE_ID ,
247+ 'request-1' ,
248+ SOURCE_USER_ID
249+ )
250+
251+ expect ( mockGetBoundWorkspaceFileSecretProvenanceByMetadata ) . toHaveBeenCalledWith (
252+ expect . anything ( ) ,
253+ [ mothershipBinding ]
254+ )
255+ expect ( findDocumentProvenanceWrite ( ) ) . toEqual (
256+ expect . objectContaining ( {
257+ status : 'exact' ,
258+ entries : [ expect . objectContaining ( { name : 'CHAT_SECRET' } ) ] ,
259+ } )
260+ )
261+ } )
262+
196263 it ( 'preserves legacy behavior when a workspace source has no metadata binding' , async ( ) => {
197264 mockGetFileMetadataByKeys . mockResolvedValue ( [ ] )
198265
@@ -221,7 +288,7 @@ describe('knowledge workspace source provenance', () => {
221288 'request-1'
222289 )
223290
224- expect ( mockGetFileMetadataByKeys ) . toHaveBeenCalledWith ( [ SOURCE_KEY ] , 'knowledge-base' )
291+ expect ( mockGetFileMetadataByKeys ) . not . toHaveBeenCalled ( )
225292 expect ( mockDeleteFile ) . not . toHaveBeenCalled ( )
226293 expect ( mockDeleteFileMetadataByIdentity ) . not . toHaveBeenCalled ( )
227294 } )
0 commit comments