@@ -10,6 +10,7 @@ import {
1010 outboxEvent ,
1111 permissions ,
1212 user ,
13+ workflowTest ,
1314 workspace ,
1415 workspaceFileSecretProvenance ,
1516 workspaceFiles ,
@@ -43,6 +44,7 @@ import { createAgentCliTransport } from '@/lib/mothership/agent-cli/transport'
4344import { handoffFileCreatorsInTx } from '@/lib/uploads/contexts/workspace/creator-handoff'
4445import { WORKSPACE_FILE_STORAGE_CLEANUP_OUTBOX_EVENT } from '@/lib/uploads/contexts/workspace/file-outbox-events'
4546import {
47+ createOwnedWorkspaceFile ,
4648 deleteWorkspaceFileVersion ,
4749 fetchWorkspaceFileBuffer ,
4850 getWorkspaceFile ,
@@ -64,13 +66,7 @@ import {
6466 releaseWorkspaceFileVersionsForPurgeInTx ,
6567} from '@/lib/uploads/contexts/workspace/workspace-file-versions'
6668import * as storageService from '@/lib/uploads/core/storage-service'
67- import { v2FileErrorPolicies } from '@/lib/workspace-files/api'
68- import { presentWorkspaceFileText } from '@/lib/workspace-files/api/text-presenter'
69- import {
70- downloadWorkspaceFileVersion ,
71- readWorkspaceFileVersionText ,
72- revertWorkspaceFileVersion ,
73- } from '@/lib/workspace-files/application/file-versions'
69+ import { revertWorkspaceFileVersion } from '@/lib/workspace-files/application/file-versions'
7470import { revokeWorkspaceAccessTx } from '@/lib/workspaces/access/workspace-access'
7571import { runCleanupFileVersions } from '@/background/cleanup-file-versions'
7672import { runCleanupSoftDeletes } from '@/background/cleanup-soft-deletes'
@@ -355,6 +351,7 @@ describe('workspace file version history in PostgreSQL', () => {
355351 )
356352
357353 it . each ( [
354+ { operation : 'owned' , enqueueAvailable : true , code : 'CONNECTION_CLOSED' } ,
358355 { operation : 'upload' , enqueueAvailable : true , code : undefined } ,
359356 { operation : 'content' , enqueueAvailable : true , code : undefined } ,
360357 { operation : 'upload' , enqueueAvailable : false , code : undefined } ,
@@ -389,23 +386,41 @@ describe('workspace file version history in PostgreSQL', () => {
389386 } )
390387 try {
391388 const result =
392- operation === 'content'
393- ? updateWorkspaceFileContent (
394- fixture . workspaceId ,
395- fixture . fileId ,
396- fixture . aliceId ,
397- Buffer . from ( 'committed content' ) ,
398- undefined ,
399- { version : { source : 'api' , authorUserId : fixture . aliceId } }
400- )
401- : uploadWorkspaceFile (
402- fixture . workspaceId ,
403- fixture . aliceId ,
404- Buffer . from ( 'committed content' ) ,
405- 'committed.txt' ,
406- 'text/plain' ,
407- { notifyWorkspaceChange : false }
408- )
389+ operation === 'owned'
390+ ? createOwnedWorkspaceFile ( {
391+ context : 'test' ,
392+ workspaceId : fixture . workspaceId ,
393+ userId : fixture . aliceId ,
394+ content : 'committed content' ,
395+ contentType : 'text/plain' ,
396+ fileName : ( id ) => `${ id } .txt` ,
397+ insertOwner : async ( tx , bodyFileId ) =>
398+ tx . insert ( workflowTest ) . values ( {
399+ id : generateId ( ) ,
400+ workspaceId : fixture . workspaceId ,
401+ name : generateId ( ) ,
402+ title : 'Commit outcome' ,
403+ bodyFileId,
404+ sourceHash : 'fixture' ,
405+ } ) ,
406+ } )
407+ : operation === 'content'
408+ ? updateWorkspaceFileContent (
409+ fixture . workspaceId ,
410+ fixture . fileId ,
411+ fixture . aliceId ,
412+ Buffer . from ( 'committed content' ) ,
413+ undefined ,
414+ { version : { source : 'api' , authorUserId : fixture . aliceId } }
415+ )
416+ : uploadWorkspaceFile (
417+ fixture . workspaceId ,
418+ fixture . aliceId ,
419+ Buffer . from ( 'committed content' ) ,
420+ 'committed.txt' ,
421+ 'text/plain' ,
422+ { notifyWorkspaceChange : false }
423+ )
409424 await expect ( result ) . rejects . toThrow ( 'Commit acknowledgement lost' )
410425 } finally {
411426 capture . mockRestore ( )
@@ -417,11 +432,15 @@ describe('workspace file version history in PostgreSQL', () => {
417432 . from ( workspaceFiles )
418433 . where ( eq ( workspaceFiles . key , stagedKey ) )
419434 expect ( committed ?. id ) . toEqual ( expect . any ( String ) )
420- const file = await getWorkspaceFile ( fixture . workspaceId , committed . id )
421- if ( ! file ) throw new Error ( 'committed file missing' )
422- expect ( ( await fetchWorkspaceFileBuffer ( file , { maxBytes : 1024 } ) ) . toString ( ) ) . toBe (
423- 'committed content'
424- )
435+ expect (
436+ (
437+ await storageService . downloadFile ( {
438+ key : stagedKey ,
439+ context : 'workspace' ,
440+ maxBytes : 1024 ,
441+ } )
442+ ) . toString ( )
443+ ) . toBe ( 'committed content' )
425444 expect (
426445 await db
427446 . select ( { id : outboxEvent . id } )
0 commit comments