Skip to content

Commit 4d2c6b3

Browse files
committed
refactor(uploads): move the external URL fetch out of the workspace files module
1 parent b06840e commit 4d2c6b3

7 files changed

Lines changed: 8 additions & 18 deletions

File tree

‎.agents/skills/memory-load-check/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Read these when doing a deeper pass:
4545
- dispatch concrete chunks (`workspaceIds`, retention, label) instead of one giant scope
4646
- prefer Trigger.dev queue/concurrency keys when available
4747
- execute inline fallback chunks sequentially, not with unbounded `Promise.all`
48-
- File parse pattern in `apps/sim/lib/internal/file/parser.ts` and `apps/sim/lib/uploads/contexts/workspace/fetch-external-url.ts`
48+
- File parse pattern in `apps/sim/lib/internal/file/parser.ts` and `apps/sim/lib/uploads/utils/fetch-external-url.server.ts`
4949
- cap downloads and parsed output separately
5050
- preserve partial results when a later item exceeds the cap
5151
- never read untrusted response bodies without a byte cap

‎apps/sim/lib/internal/file/parser.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ import {
3535
} from '@/lib/internal/file/operations'
3636
import { isUsingCloudStorage, StorageService } from '@/lib/uploads'
3737
import { uploadExecutionFile } from '@/lib/uploads/contexts/execution'
38-
import { ExternalUrlValidationError, fetchExternalUrl } from '@/lib/uploads/contexts/workspace'
3938
import {
4039
getBoundWorkspaceFileSecretProvenance,
4140
type WorkspaceFileSecretProvenance,
4241
} from '@/lib/uploads/contexts/workspace/workspace-file-secret-provenance'
4342
import { UPLOAD_DIR_SERVER } from '@/lib/uploads/core/setup.server'
4443
import { isWorkspaceScopedContext } from '@/lib/uploads/shared/types'
44+
import {
45+
ExternalUrlValidationError,
46+
fetchExternalUrl,
47+
} from '@/lib/uploads/utils/fetch-external-url.server'
4548
import {
4649
extractCleanFilename,
4750
extractStorageKey,
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export * from './fetch-external-url'
21
export * from './workspace-file-folder-manager'
32
export * from './workspace-file-manager'

apps/sim/lib/uploads/contexts/workspace/fetch-external-url.test.ts renamed to apps/sim/lib/uploads/utils/fetch-external-url.server.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as inputValidation from '@/lib/core/security/input-validation.server'
1111
import {
1212
ExternalUrlValidationError,
1313
fetchExternalUrl,
14-
} from '@/lib/uploads/contexts/workspace/fetch-external-url'
14+
} from '@/lib/uploads/utils/fetch-external-url.server'
1515

1616
let validateUrlWithDNSSpy: MockInstance<typeof inputValidation.validateUrlWithDNS>
1717
let secureFetchWithPinnedIPSpy: MockInstance<typeof inputValidation.secureFetchWithPinnedIP>

apps/sim/lib/uploads/contexts/workspace/fetch-external-url.ts renamed to apps/sim/lib/uploads/utils/fetch-external-url.server.ts

File renamed without changes.

‎packages/testing/src/mocks/index.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@ export {
10441044
workspaceForkingMappingStoreMockFns,
10451045
} from './workspace-forking-mapping-store.mock'
10461046
export {
1047-
MockExternalUrlValidationError,
10481047
MockWorkspaceFileFolderConflictError,
10491048
MockWorkspaceFileItemsNotFoundError,
10501049
MockWorkspaceFileMoveConflictError,

‎packages/testing/src/mocks/workspace-uploads.mock.ts‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ export class MockWorkspaceFileItemsNotFoundError extends Error {
4141
}
4242
}
4343

44-
/** Real `ExternalUrlValidationError` stand-in: same `name` and message. */
45-
export class MockExternalUrlValidationError extends Error {
46-
constructor(message: string) {
47-
super(message)
48-
this.name = 'ExternalUrlValidationError'
49-
}
50-
}
51-
5244
/** Structural stand-in for a folder row passed to `buildWorkspaceFileFolderPathMap`. */
5345
interface MockFolderPathRow {
5446
id: string
@@ -57,7 +49,7 @@ interface MockFolderPathRow {
5749
}
5850

5951
/**
60-
* Controllable mock functions for the folder-manager and external-URL halves of the
52+
* Controllable mock functions for the folder-manager half of the
6153
* `@/lib/uploads/contexts/workspace` barrel. The file-manager half is
6254
* `workspaceFileManagerMockFns` (re-exported here as `...workspaceFileManagerMockFns`).
6355
*
@@ -75,7 +67,6 @@ interface MockFolderPathRow {
7567
*/
7668
export const workspaceUploadsMockFns = {
7769
...workspaceFileManagerMockFns,
78-
mockFetchExternalUrl: vi.fn(),
7970
mockLoadWorkspaceFileOperationContext: vi.fn(),
8071
mockAssertWorkspaceFileItemsBelongToWorkspace: vi.fn(),
8172
mockNormalizeWorkspaceFileItemName: vi.fn((name: string, itemLabel: 'File' | 'Folder') => {
@@ -128,7 +119,7 @@ const fns = workspaceUploadsMockFns
128119

129120
/**
130121
* Static mock module for the `@/lib/uploads/contexts/workspace` barrel
131-
* (`workspace-file-manager` + `workspace-file-folder-manager` + `fetch-external-url`).
122+
* (`workspace-file-manager` + `workspace-file-folder-manager`).
132123
*
133124
* The error classes extend `Error`, not `OrchestrationError`: their `name`, `code` and
134125
* message match production, but `instanceof OrchestrationError` is false.
@@ -140,11 +131,9 @@ const fns = workspaceUploadsMockFns
140131
*/
141132
export const workspaceUploadsMock = {
142133
...workspaceFileManagerMock,
143-
ExternalUrlValidationError: MockExternalUrlValidationError,
144134
WorkspaceFileFolderConflictError: MockWorkspaceFileFolderConflictError,
145135
WorkspaceFileMoveConflictError: MockWorkspaceFileMoveConflictError,
146136
WorkspaceFileItemsNotFoundError: MockWorkspaceFileItemsNotFoundError,
147-
fetchExternalUrl: fns.mockFetchExternalUrl,
148137
loadWorkspaceFileOperationContext: fns.mockLoadWorkspaceFileOperationContext,
149138
assertWorkspaceFileItemsBelongToWorkspace: fns.mockAssertWorkspaceFileItemsBelongToWorkspace,
150139
normalizeWorkspaceFileItemName: fns.mockNormalizeWorkspaceFileItemName,

0 commit comments

Comments
 (0)