chore: import upstream snapshot with attribution
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
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
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
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* @vitest-environment node
|
||||
*/
|
||||
import { dbChainMock, dbChainMockFns, resetDbChainMock } from '@sim/testing'
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import type { DbOrTx } from '@/lib/db/types'
|
||||
import {
|
||||
listForkCopyableSourceResources,
|
||||
listForkResourceCandidates,
|
||||
loadForkCopyableResourceLabels,
|
||||
} from '@/ee/workspace-forking/lib/mapping/resources'
|
||||
|
||||
const executor = dbChainMock.db as unknown as DbOrTx
|
||||
|
||||
describe('listForkResourceCandidates', () => {
|
||||
beforeEach(() => {
|
||||
resetDbChainMock()
|
||||
})
|
||||
|
||||
it('populates file candidates keyed by storage key and leaves knowledge-document empty', async () => {
|
||||
// The grouped queries resolve in Promise.all array order, each ending in `.limit()`:
|
||||
// credentials, workspace env, tables, knowledge bases, MCP servers, custom tools, skills,
|
||||
// files. Queue the eight results in that exact order.
|
||||
dbChainMockFns.limit
|
||||
.mockResolvedValueOnce([
|
||||
{ id: 'cred-1', displayName: 'Cred One', providerId: 'google-email' },
|
||||
])
|
||||
.mockResolvedValueOnce([{ variables: { API_KEY: 'secret' } }])
|
||||
.mockResolvedValueOnce([{ id: 'tbl-1', label: 'Table One' }])
|
||||
.mockResolvedValueOnce([{ id: 'kb-1', label: 'KB One' }])
|
||||
.mockResolvedValueOnce([{ id: 'mcp-1', label: 'MCP One' }])
|
||||
.mockResolvedValueOnce([{ id: 'ct-1', label: 'Tool One' }])
|
||||
.mockResolvedValueOnce([{ id: 'sk-1', label: 'Skill One' }])
|
||||
.mockResolvedValueOnce([
|
||||
{ id: 'workspace/WS/report.pdf', label: 'report.pdf' },
|
||||
{ id: 'workspace/WS/notes.md', label: 'notes.md' },
|
||||
])
|
||||
|
||||
const result = await listForkResourceCandidates(executor, 'ws-1')
|
||||
|
||||
// Files are mapping targets keyed by storage key (matching how `file-upload` references store
|
||||
// them) - never a `workspace_files.id`.
|
||||
expect(result.file).toEqual([
|
||||
{ id: 'workspace/WS/report.pdf', label: 'report.pdf' },
|
||||
{ id: 'workspace/WS/notes.md', label: 'notes.md' },
|
||||
])
|
||||
// Documents are not a standalone mappable kind - they ride their KB via the reconfigure flow.
|
||||
expect(result['knowledge-document']).toEqual([])
|
||||
expect(result['env-var']).toEqual([{ id: 'API_KEY', label: 'API_KEY' }])
|
||||
})
|
||||
})
|
||||
|
||||
describe('listForkCopyableSourceResources', () => {
|
||||
beforeEach(() => {
|
||||
resetDbChainMock()
|
||||
})
|
||||
|
||||
it('lists every sync-copyable kind, files keyed by storage key with folder grouping', async () => {
|
||||
// The grouped queries resolve in Promise.all array order, each ending in `.limit()`:
|
||||
// files (with folder), tables, knowledge bases, custom tools, skills.
|
||||
dbChainMockFns.limit
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
id: 'file-row-1',
|
||||
key: 'workspace/SRC/a.png',
|
||||
label: 'a.png',
|
||||
folderId: 'fld-1',
|
||||
folderName: 'Images',
|
||||
},
|
||||
{
|
||||
id: 'file-row-2',
|
||||
key: 'workspace/SRC/root.txt',
|
||||
label: 'root.txt',
|
||||
folderId: null,
|
||||
folderName: null,
|
||||
},
|
||||
])
|
||||
.mockResolvedValueOnce([{ id: 'tbl-1', label: 'Table One' }])
|
||||
.mockResolvedValueOnce([{ id: 'kb-1', label: 'KB One' }])
|
||||
.mockResolvedValueOnce([{ id: 'ct-1', label: 'Tool One' }])
|
||||
.mockResolvedValueOnce([{ id: 'sk-1', label: 'Skill One' }])
|
||||
|
||||
const result = await listForkCopyableSourceResources(executor, 'ws-src')
|
||||
|
||||
expect(result).toEqual([
|
||||
// Files are addressed by STORAGE KEY (matching `file-upload` references + the promote copy
|
||||
// selection), never by `workspace_files.id`, and carry their folder grouping.
|
||||
{
|
||||
kind: 'file',
|
||||
sourceId: 'workspace/SRC/a.png',
|
||||
label: 'a.png',
|
||||
parentId: 'fld-1',
|
||||
parentLabel: 'Images',
|
||||
},
|
||||
{
|
||||
kind: 'file',
|
||||
sourceId: 'workspace/SRC/root.txt',
|
||||
label: 'root.txt',
|
||||
parentId: null,
|
||||
parentLabel: null,
|
||||
},
|
||||
{ kind: 'table', sourceId: 'tbl-1', label: 'Table One', parentId: null, parentLabel: null },
|
||||
{
|
||||
kind: 'knowledge-base',
|
||||
sourceId: 'kb-1',
|
||||
label: 'KB One',
|
||||
parentId: null,
|
||||
parentLabel: null,
|
||||
},
|
||||
{
|
||||
kind: 'custom-tool',
|
||||
sourceId: 'ct-1',
|
||||
label: 'Tool One',
|
||||
parentId: null,
|
||||
parentLabel: null,
|
||||
},
|
||||
{ kind: 'skill', sourceId: 'sk-1', label: 'Skill One', parentId: null, parentLabel: null },
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('loadForkCopyableResourceLabels', () => {
|
||||
beforeEach(() => {
|
||||
resetDbChainMock()
|
||||
})
|
||||
|
||||
it('carries the folder grouping for file entries (id + name, null at the root)', async () => {
|
||||
// Only the file branch queries (no other kind has ids), so its terminal `.where()` is the
|
||||
// single chain call.
|
||||
dbChainMockFns.where.mockResolvedValueOnce([
|
||||
{ key: 'workspace/SRC/a.png', label: 'a.png', folderId: 'fld-1', folderName: 'Images' },
|
||||
{ key: 'workspace/SRC/root.txt', label: 'root.txt', folderId: null, folderName: null },
|
||||
])
|
||||
|
||||
const labels = await loadForkCopyableResourceLabels(executor, 'ws-src', {
|
||||
file: ['workspace/SRC/a.png', 'workspace/SRC/root.txt'],
|
||||
})
|
||||
|
||||
expect(labels.get('file:workspace/SRC/a.png')).toEqual({
|
||||
label: 'a.png',
|
||||
parentId: 'fld-1',
|
||||
parentLabel: 'Images',
|
||||
})
|
||||
// A file at the workspace root (or whose folder was deleted) carries null folder grouping.
|
||||
expect(labels.get('file:workspace/SRC/root.txt')).toEqual({
|
||||
label: 'root.txt',
|
||||
parentId: null,
|
||||
parentLabel: null,
|
||||
})
|
||||
})
|
||||
|
||||
it('returns null folder grouping for non-file kinds (they render flat)', async () => {
|
||||
dbChainMockFns.where.mockResolvedValueOnce([{ id: 'kb-1', label: 'KB One' }])
|
||||
|
||||
const labels = await loadForkCopyableResourceLabels(executor, 'ws-src', {
|
||||
'knowledge-base': ['kb-1'],
|
||||
})
|
||||
|
||||
expect(labels.get('knowledge-base:kb-1')).toEqual({
|
||||
label: 'KB One',
|
||||
parentId: null,
|
||||
parentLabel: null,
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user