Skip to content

Commit 0077285

Browse files
committed
chore(files): tidy archive extraction cleanup
1 parent 94fa43b commit 0077285

2 files changed

Lines changed: 6 additions & 25 deletions

File tree

apps/sim/lib/uploads/archive.test.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,22 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
1111
* and the folder/file layers, not in the extractor's own arithmetic. The fake
1212
* therefore enforces the real rules:
1313
*
14-
* - folder paths are validated with the production {@link parseFolderPath} family,
15-
* so a non-canonical path (no leading slash, unencoded segment) throws exactly
16-
* as `requireNonRootFolderPath` does in `workspace-file-folder-manager`;
17-
* - `createWorkspaceFileFolderOperation` creates ONE leaf and rejects an existing
18-
* path or a missing parent, mirroring `createWorkspaceFileFolderAtPath`;
14+
* - folder keys are built with the production {@link buildFolderPath}, so a segment
15+
* that needs encoding is rejected or encoded exactly as the folder layer would;
1916
* - `exactName: true` throws `FileConflictError` on a duplicate leaf name, while
2017
* `exactName: false` auto-suffixes, mirroring `uploadWorkspaceFile`.
2118
*/
22-
const { store, mockUpload, mockDelete, mockCreateFolder, mockEnsureFolder } = vi.hoisted(() => ({
19+
const { store, mockUpload, mockDelete, mockEnsureFolder } = vi.hoisted(() => ({
2320
store: {
2421
folderIdByPath: new Map<string, string>(),
2522
fileKeys: new Set<string>(),
2623
sequence: 0,
2724
},
2825
mockUpload: vi.fn(),
2926
mockDelete: vi.fn(),
30-
mockCreateFolder: vi.fn(),
3127
mockEnsureFolder: vi.fn(),
3228
}))
3329
vi.mock('@/lib/workspace-files/application/workspace-file-folders', () => ({
34-
createWorkspaceFileFolderOperation: { execute: mockCreateFolder },
3530
ensureWorkspaceFileFolderPathOperation: { execute: mockEnsureFolder },
3631
}))
3732
vi.mock('@/lib/workspace-files/application/create-workspace-file', () => ({
@@ -45,7 +40,7 @@ vi.mock('@/lib/workspace-files/application/delete-workspace-file', () => ({
4540
},
4641
}))
4742

48-
import { buildFolderPath, requireNonRootFolderPath } from '@/lib/folders/paths'
43+
import { buildFolderPath } from '@/lib/folders/paths'
4944
import {
5045
decompressArchiveBufferToWorkspaceFiles,
5146
MAX_ARCHIVE_CENTRAL_DIR_EXTRA_BYTES,
@@ -125,20 +120,6 @@ beforeEach(() => {
125120
store.fileKeys.clear()
126121
store.sequence = 0
127122

128-
mockCreateFolder.mockImplementation(async ({ input }: { input: { path: string } }) => {
129-
const segments = requireNonRootFolderPath(input.path)
130-
if (store.folderIdByPath.has(input.path)) {
131-
throw new Error(`A folder named "${segments[segments.length - 1]}" already exists`)
132-
}
133-
const parentPath = buildFolderPath(segments.slice(0, -1))
134-
if (parentPath !== '/' && !store.folderIdByPath.has(parentPath)) {
135-
throw new Error('Parent folder not found')
136-
}
137-
const id = `folder_${++store.sequence}`
138-
store.folderIdByPath.set(input.path, id)
139-
return { folder: { id, path: input.path } }
140-
})
141-
142123
mockEnsureFolder.mockImplementation(async ({ input }: { input: { pathSegments: string[] } }) => {
143124
let folderId: string | null = null
144125
const walked: string[] = []

apps/sim/lib/workspace-files/application/workspace-file-folders.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ export const createWorkspaceFileFolderOperation = defineAuthorizedWorkspaceFileU
272272
* Idempotently materializes a whole folder chain, reusing every folder that already
273273
* exists and creating only the missing ones. Unlike {@link createWorkspaceFileFolderOperation}
274274
* — which creates exactly one leaf and fails on an existing path or a missing parent —
275-
* this is the primitive for writers that materialize a tree (archive extraction, workspace
276-
* import), where intermediate folders and repeat runs are expected rather than exceptional.
275+
* this is the primitive for writers that materialize a tree (archive extraction), where
276+
* intermediate folders and repeat runs are expected rather than exceptional.
277277
*/
278278
export const ensureWorkspaceFileFolderPathOperation = defineAuthorizedWorkspaceFileUseCase({
279279
operation: fileOperations.createFolder,

0 commit comments

Comments
 (0)