@@ -132,8 +132,10 @@ import {
132132 resolveInputFiles ,
133133} from '@/lib/mothership/tools/handlers/function-execute'
134134import { chatSandboxSessionKey } from '@/lib/mothership/tools/sandbox-session-key'
135+ import { writeCopilotWorkspaceFileByPath } from '@/lib/mothership/vfs/resource-writer'
135136import { replaceWorkflowNormalizedState } from '@/lib/workflows/persistence/replace-normalized-state'
136137import { fileOperations } from '@/lib/workspace-files/application/operations'
138+ import { readWorkspaceFileArtifact } from '@/lib/workspace-files/application/read-workspace-file-artifact'
137139import { readWorkspaceFileText } from '@/lib/workspace-files/application/read-workspace-file-text'
138140import {
139141 POST as addChatResourceRoute ,
@@ -2222,7 +2224,13 @@ describe.skipIf(!process.env.MSHIP_TEST_DATABASE_URL)(
22222224
22232225 it
22242226 . skipIf ( ! process . env . MSHIP_LOCAL_COMPUTE_IMAGE || ! process . env . MSHIP_WORKER_ROOT )
2225- . each ( [ 'returned-value' , 'sandbox-file' , 'mixed-files' , 'missing-table' ] as const ) (
2227+ . each ( [
2228+ 'returned-value' ,
2229+ 'sandbox-file' ,
2230+ 'mixed-files' ,
2231+ 'missing-table' ,
2232+ 'partial-files' ,
2233+ ] as const ) (
22262234 'composes attachment computation, table replacement, durable export and fresh-chat re-import: %s' ,
22272235 async ( mode ) => {
22282236 fixture . permission = 'write'
@@ -2360,6 +2368,15 @@ describe.skipIf(!process.env.MSHIP_TEST_DATABASE_URL)(
23602368 expect ( prepared . storedAttachments ) . toHaveLength ( 1 )
23612369 await vi . mocked ( executeShellInSandbox ) . withImplementation ( compute , async ( ) => {
23622370 const callContext = context ( chatId )
2371+ if ( mode === 'partial-files' ) {
2372+ await writeCopilotWorkspaceFileByPath ( callContext , {
2373+ workspaceId,
2374+ target : { path : `files/existing-${ exportName } ` , mode : 'create' } ,
2375+ buffer : Buffer . from ( 'Existing report must survive' ) ,
2376+ inferredMimeType : 'text/csv' ,
2377+ secretProvenance : { status : 'exact' , entries : [ ] } ,
2378+ } )
2379+ }
23632380 const params = {
23642381 language : 'shell' ,
23652382 timeout : 30 ,
@@ -2376,16 +2393,17 @@ describe.skipIf(!process.env.MSHIP_TEST_DATABASE_URL)(
23762393 ...( mode === 'mixed-files'
23772394 ? [ { path : `files/raw-${ exportName } ` , sandboxPath : '/home/user/totals.csv' } ]
23782395 : [ ] ) ,
2396+ ...( mode === 'partial-files' ? [ { path : `files/existing-${ exportName } ` } ] : [ ] ) ,
23792397 ] ,
23802398 } ,
23812399 outputTable : mode === 'missing-table' ? generateId ( ) : tableId ,
23822400 }
23832401 let result = await executeFunctionExecute ( params , callContext )
23842402 expect ( result . success , JSON . stringify ( result ) ) . toBe ( true )
23852403 result = await maybeWriteOutputToFile ( 'run_function' , params , result , callContext )
2386- expect ( result . success , JSON . stringify ( result ) ) . toBe ( true )
2404+ expect ( result . success , JSON . stringify ( result ) ) . toBe ( mode !== 'partial-files' )
23872405 result = await maybeWriteOutputToTable ( 'run_function' , params , result , callContext )
2388- if ( mode === 'missing-table' ) {
2406+ if ( mode === 'missing-table' || mode === 'partial-files' ) {
23892407 expect ( result . success ) . toBe ( false )
23902408 expect ( result . error ) . toContain ( 'already written' )
23912409 expect ( result . output ) . toMatchObject ( {
@@ -2414,7 +2432,7 @@ describe.skipIf(!process.env.MSHIP_TEST_DATABASE_URL)(
24142432 . from ( userTableRows )
24152433 . where ( eq ( userTableRows . tableId , tableId ) )
24162434 const expectedRows =
2417- mode === 'missing-table'
2435+ mode === 'missing-table' || mode === 'partial-files'
24182436 ? [ ]
24192437 : [
24202438 { col_account : 'alpha' , col_total : 22 } ,
@@ -2443,6 +2461,13 @@ describe.skipIf(!process.env.MSHIP_TEST_DATABASE_URL)(
24432461 sandboxSession : 'created' ,
24442462 } )
24452463 expect ( sessions . size ) . toBe ( 2 )
2464+ if ( mode === 'partial-files' ) {
2465+ const existing = await readWorkspaceFileArtifact . execute ( {
2466+ principal : { kind : 'personal_api_key' , userId : 'run-reader' , keyId : 'local-key' } ,
2467+ input : { workspaceId, reference : `files/existing-${ exportName } ` , maxBytes : 1024 } ,
2468+ } )
2469+ expect ( existing . buffer . toString ( 'utf8' ) ) . toBe ( 'Existing report must survive' )
2470+ }
24462471 } )
24472472 } finally {
24482473 setEnvFlags ( { isMothershipSandboxEnabled : previousWorkbenchEnabled } )
0 commit comments