d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
242 lines
6.9 KiB
TypeScript
242 lines
6.9 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { FileV4Block, FileV5Block } from '@/blocks/blocks/file'
|
|
|
|
describe('FileV4Block', () => {
|
|
const buildParams = FileV4Block.tools.config.params
|
|
|
|
it('accepts http and https URLs for fetch', () => {
|
|
expect(
|
|
buildParams({
|
|
operation: 'file_fetch',
|
|
fileUrl: 'https://example.com/image.jpg',
|
|
_context: {
|
|
workspaceId: 'workspace-1',
|
|
workflowId: 'workflow-1',
|
|
executionId: 'execution-1',
|
|
},
|
|
})
|
|
).toMatchObject({
|
|
filePath: 'https://example.com/image.jpg',
|
|
workspaceId: 'workspace-1',
|
|
workflowId: 'workflow-1',
|
|
executionId: 'execution-1',
|
|
})
|
|
})
|
|
|
|
it('rejects inline content for fetch', () => {
|
|
expect(() =>
|
|
buildParams({
|
|
operation: 'file_fetch',
|
|
fileUrl: '\u0001\u0002raw jpeg bytes',
|
|
})
|
|
).toThrow('File URL must be a valid http or https URL')
|
|
})
|
|
|
|
it('rejects data URLs for fetch', () => {
|
|
expect(() =>
|
|
buildParams({
|
|
operation: 'file_fetch',
|
|
fileUrl: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD',
|
|
})
|
|
).toThrow('File URL must use http or https')
|
|
})
|
|
|
|
it('rejects valid URLs with unsupported protocols for fetch', () => {
|
|
expect(() =>
|
|
buildParams({
|
|
operation: 'file_fetch',
|
|
fileUrl: 'ftp://example.com/file.pdf',
|
|
})
|
|
).toThrow('File URL must use http or https')
|
|
})
|
|
})
|
|
|
|
describe('FileV5Block', () => {
|
|
const buildParams = FileV5Block.tools.config.params
|
|
|
|
it('maps each operation directly to its tool', () => {
|
|
expect(FileV5Block.tools.config.tool({ operation: 'file_read' })).toBe('file_read')
|
|
expect(FileV5Block.tools.config.tool({ operation: 'file_get_content' })).toBe(
|
|
'file_get_content'
|
|
)
|
|
expect(FileV5Block.tools.config.tool({ operation: 'file_fetch' })).toBe('file_fetch')
|
|
expect(FileV5Block.tools.config.tool({ operation: 'file_write' })).toBe('file_write')
|
|
expect(FileV5Block.tools.config.tool({ operation: 'file_append' })).toBe('file_append')
|
|
})
|
|
|
|
it('read returns only the files output (no redundant file)', () => {
|
|
expect(FileV5Block.outputs.files).toBeDefined()
|
|
expect(FileV5Block.outputs.contents).toBeDefined()
|
|
expect(FileV5Block.outputs.file).toBeUndefined()
|
|
})
|
|
|
|
it('resolves canonical IDs for get content', () => {
|
|
expect(
|
|
buildParams({
|
|
operation: 'file_get_content',
|
|
getContentInput: '["file-1","file-2"]',
|
|
_context: { workspaceId: 'workspace-1' },
|
|
})
|
|
).toEqual({
|
|
fileId: ['file-1', 'file-2'],
|
|
workspaceId: 'workspace-1',
|
|
})
|
|
})
|
|
|
|
it('resolves selected file objects for get content', () => {
|
|
expect(
|
|
buildParams({
|
|
operation: 'file_get_content',
|
|
getContentInput: [
|
|
{
|
|
key: 'workspace/workspace-1/notes.md',
|
|
name: 'notes.md',
|
|
path: '/api/files/serve/workspace%2Fworkspace-1%2Fnotes.md?context=workspace',
|
|
size: 10,
|
|
type: 'text/markdown',
|
|
},
|
|
],
|
|
_context: { workspaceId: 'workspace-1' },
|
|
})
|
|
).toEqual({
|
|
fileInput: [
|
|
{
|
|
key: 'workspace/workspace-1/notes.md',
|
|
name: 'notes.md',
|
|
path: '/api/files/serve/workspace%2Fworkspace-1%2Fnotes.md?context=workspace',
|
|
size: 10,
|
|
type: 'text/markdown',
|
|
},
|
|
],
|
|
workspaceId: 'workspace-1',
|
|
})
|
|
})
|
|
|
|
it('throws when no file is provided for get content', () => {
|
|
expect(() => buildParams({ operation: 'file_get_content' })).toThrow(
|
|
'File is required for get content'
|
|
)
|
|
})
|
|
|
|
it('maps manage sharing to public access for a canonical file ID', () => {
|
|
expect(
|
|
buildParams({
|
|
operation: 'file_manage_sharing',
|
|
shareInput: 'file-1',
|
|
shareVisibility: 'public',
|
|
_context: { workspaceId: 'workspace-1' },
|
|
})
|
|
).toEqual({
|
|
fileId: 'file-1',
|
|
isActive: true,
|
|
authType: 'public',
|
|
password: undefined,
|
|
allowedEmails: undefined,
|
|
workspaceId: 'workspace-1',
|
|
})
|
|
})
|
|
|
|
it('maps private visibility to a disabled share with no authType', () => {
|
|
expect(
|
|
buildParams({
|
|
operation: 'file_manage_sharing',
|
|
shareInput: 'file-1',
|
|
shareVisibility: 'private',
|
|
_context: { workspaceId: 'workspace-1' },
|
|
})
|
|
).toMatchObject({
|
|
fileId: 'file-1',
|
|
isActive: false,
|
|
authType: undefined,
|
|
})
|
|
})
|
|
|
|
it('passes the password through for password visibility', () => {
|
|
expect(
|
|
buildParams({
|
|
operation: 'file_manage_sharing',
|
|
shareInput: 'file-1',
|
|
shareVisibility: 'password',
|
|
sharePassword: 'hunter2',
|
|
_context: { workspaceId: 'workspace-1' },
|
|
})
|
|
).toMatchObject({
|
|
fileId: 'file-1',
|
|
isActive: true,
|
|
authType: 'password',
|
|
password: 'hunter2',
|
|
})
|
|
})
|
|
|
|
it('splits allowed emails for email visibility', () => {
|
|
expect(
|
|
buildParams({
|
|
operation: 'file_manage_sharing',
|
|
shareInput: 'file-1',
|
|
shareVisibility: 'email',
|
|
shareAllowedEmails: 'a@example.com, b@example.com\n@acme.com',
|
|
_context: { workspaceId: 'workspace-1' },
|
|
})
|
|
).toMatchObject({
|
|
fileId: 'file-1',
|
|
isActive: true,
|
|
authType: 'email',
|
|
allowedEmails: ['a@example.com', 'b@example.com', '@acme.com'],
|
|
})
|
|
})
|
|
|
|
it('resolves the file ID from a selected workspace file object for manage sharing', () => {
|
|
expect(
|
|
buildParams({
|
|
operation: 'file_manage_sharing',
|
|
shareInput: [{ id: 'file-9', name: 'report.pdf' }],
|
|
shareVisibility: 'public',
|
|
_context: { workspaceId: 'workspace-1' },
|
|
})
|
|
).toMatchObject({
|
|
fileId: 'file-9',
|
|
isActive: true,
|
|
authType: 'public',
|
|
})
|
|
})
|
|
|
|
it('passes a picker file object without an id through as fileInput for manage sharing', () => {
|
|
const picked = {
|
|
name: 'report.pdf',
|
|
key: 'workspace/workspace-1/123-abc-report.pdf',
|
|
path: '/api/files/serve/workspace%2Fworkspace-1%2F123-abc-report.pdf?context=workspace',
|
|
size: 10,
|
|
type: 'application/pdf',
|
|
}
|
|
expect(
|
|
buildParams({
|
|
operation: 'file_manage_sharing',
|
|
shareInput: [picked],
|
|
shareVisibility: 'public',
|
|
_context: { workspaceId: 'workspace-1' },
|
|
})
|
|
).toMatchObject({
|
|
fileInput: picked,
|
|
isActive: true,
|
|
authType: 'public',
|
|
})
|
|
})
|
|
|
|
it('throws when no file is provided for manage sharing', () => {
|
|
expect(() => buildParams({ operation: 'file_manage_sharing' })).toThrow(
|
|
'File is required to manage sharing'
|
|
)
|
|
})
|
|
|
|
it('rejects multiple file IDs for manage sharing', () => {
|
|
expect(() =>
|
|
buildParams({
|
|
operation: 'file_manage_sharing',
|
|
shareInput: '["file-1","file-2"]',
|
|
shareVisibility: 'public',
|
|
_context: { workspaceId: 'workspace-1' },
|
|
})
|
|
).toThrow('Manage Sharing accepts a single file at a time')
|
|
})
|
|
})
|