mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 12:24:39 +00:00
feat(storage): add archive storage support for assets
This commit is contained in:
@@ -97,6 +97,7 @@ apps/web/e2e/
|
||||
| Image share with watermark + download disabled: no download buttons on public list/detail pages, watermarked proxy served, download-url rejected | `tests/project/share-watermark-no-download.spec.ts` |
|
||||
| Video share with watermark + download disabled: no download buttons on public list/detail pages, watermarked proxy served, download-url rejected | `tests/project/share-watermark-no-download.spec.ts` |
|
||||
| Owner views a file and it appears in recents | `tests/project/recents.spec.ts` |
|
||||
| Owner archives a file to archive storage and restores it back to main storage | `tests/project/archive-restore.spec.ts` |
|
||||
|
||||
### file
|
||||
| Test | File |
|
||||
|
||||
@@ -10,12 +10,16 @@ export default async function globalTeardown() {
|
||||
if (fs.existsSync(envPath)) {
|
||||
const content = fs.readFileSync(envPath, 'utf8')
|
||||
let bucketName: string | undefined
|
||||
let archiveRoot: string | undefined
|
||||
|
||||
content.split('\n').forEach((line) => {
|
||||
const parts = line.split('=')
|
||||
if (parts.length >= 2 && parts[0].trim() === 'S3_BUCKET') {
|
||||
bucketName = parts.slice(1).join('=').trim()
|
||||
}
|
||||
if (parts.length >= 2 && parts[0].trim() === 'ARCHIVE_LOCAL_ROOT') {
|
||||
archiveRoot = parts.slice(1).join('=').trim()
|
||||
}
|
||||
})
|
||||
|
||||
if (bucketName) {
|
||||
@@ -26,6 +30,11 @@ export default async function globalTeardown() {
|
||||
}
|
||||
}
|
||||
|
||||
if (archiveRoot && fs.existsSync(archiveRoot)) {
|
||||
console.log(`Cleaning up E2E archive storage root: ${archiveRoot}`)
|
||||
fs.rmSync(archiveRoot, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
// Delete the temp .env.e2e file
|
||||
fs.unlinkSync(envPath)
|
||||
}
|
||||
|
||||
@@ -13,8 +13,11 @@ async function start() {
|
||||
// Generate a random S3 bucket name
|
||||
const randomSuffix = randomBytes(4).toString('hex')
|
||||
const bucketName = `shumai-e2e-${randomSuffix}`
|
||||
const archiveRoot = path.resolve('data', `shumai-e2e-archive-${randomSuffix}`)
|
||||
|
||||
process.env.S3_BUCKET = bucketName
|
||||
process.env.ARCHIVE_STORAGE_BACKEND = 'local'
|
||||
process.env.ARCHIVE_LOCAL_ROOT = archiveRoot
|
||||
process.env.SHUMAI_SERVER_PORT = '5200'
|
||||
process.env.BETTER_AUTH_URL = 'http://localhost:5200'
|
||||
process.env.NODE_ENV = 'development'
|
||||
@@ -22,9 +25,12 @@ async function start() {
|
||||
process.env.ENABLE_EMBEDDING_AGENT = 'false'
|
||||
|
||||
// Write variables to .env.e2e file so the teardown can load them
|
||||
const envContent = [`DATABASE_URL=${process.env.DATABASE_URL}`, `S3_BUCKET=${bucketName}`].join(
|
||||
'\n',
|
||||
)
|
||||
const envContent = [
|
||||
`DATABASE_URL=${process.env.DATABASE_URL}`,
|
||||
`S3_BUCKET=${bucketName}`,
|
||||
`ARCHIVE_STORAGE_BACKEND=local`,
|
||||
`ARCHIVE_LOCAL_ROOT=${archiveRoot}`,
|
||||
].join('\n')
|
||||
|
||||
fs.writeFileSync(path.resolve(currentDir, '.env.e2e'), envContent)
|
||||
console.log(`E2E env file written. Starting Web App...`)
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { fileCard } from '../../helpers/files'
|
||||
|
||||
test('owner archives a file to archive storage and restores it back to main storage', async ({
|
||||
file,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, projectId, fileName, fileId } = file
|
||||
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
const card = fileCard(page, fileName)
|
||||
await expect(card).toBeVisible()
|
||||
|
||||
// 1. Archive via context menu + confirmation dialog
|
||||
await card.click({ button: 'right' })
|
||||
await page.getByTestId('context-menu-archive').click()
|
||||
|
||||
const confirmDialog = page.getByTestId('archive-confirm-dialog')
|
||||
await expect(confirmDialog).toBeVisible()
|
||||
await page.getByTestId('archive-confirm-submit').click()
|
||||
|
||||
// Wait for the DBOS archive workflow to finish and the card badge to settle to Archived
|
||||
await expect(card.getByTestId('file-card-archived-badge')).toBeVisible({ timeout: 15000 })
|
||||
|
||||
const archivedAsset = await prisma.asset.findUniqueOrThrow({
|
||||
where: { id: fileId },
|
||||
include: { storageKey: true },
|
||||
})
|
||||
expect(archivedAsset.status).toBe('archived')
|
||||
expect(archivedAsset.storageKey?.isArchived).toBe(true)
|
||||
|
||||
// 2. Open detail page and verify Archived header badge + disabled original download button
|
||||
await card.dblclick()
|
||||
await expect(page.getByTestId('detail-header-archived-badge')).toBeVisible()
|
||||
await expect(page.getByTestId('default-viewer-download-button')).toBeDisabled()
|
||||
|
||||
// 3. Return to project file list and restore from archive
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
await expect(card.getByTestId('file-card-archived-badge')).toBeVisible()
|
||||
|
||||
await card.click({ button: 'right' })
|
||||
await page.getByTestId('context-menu-restore-archive').click()
|
||||
|
||||
await expect(confirmDialog).toBeVisible()
|
||||
await page.getByTestId('archive-confirm-submit').click()
|
||||
|
||||
// Wait for the DBOS restore workflow to finish and the Archived badge to disappear
|
||||
await expect(card.getByTestId('file-card-archived-badge')).not.toBeVisible({ timeout: 15000 })
|
||||
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
const restored = await prisma.asset.findUnique({
|
||||
where: { id: fileId },
|
||||
include: { storageKey: true },
|
||||
})
|
||||
return {
|
||||
status: restored?.status,
|
||||
isArchived: restored?.storageKey?.isArchived,
|
||||
}
|
||||
},
|
||||
{ timeout: 10000 },
|
||||
)
|
||||
.toEqual({ status: 'processed', isArchived: false })
|
||||
})
|
||||
Reference in New Issue
Block a user