d25d482dc2
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
76 lines
2.8 KiB
TypeScript
76 lines
2.8 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
vi.mock('@/lib/execution/e2b', () => ({
|
|
executeInE2B: vi.fn(),
|
|
executeShellInE2B: vi.fn(),
|
|
}))
|
|
vi.mock('@/lib/execution/languages', () => ({
|
|
CodeLanguage: { javascript: 'javascript', python: 'python' },
|
|
}))
|
|
vi.mock('@/lib/uploads/contexts/workspace/workspace-file-manager', () => ({
|
|
getWorkspaceFile: vi.fn(),
|
|
fetchWorkspaceFileBuffer: vi.fn(),
|
|
}))
|
|
vi.mock('./doc-compiled-store', () => ({
|
|
loadCompiledDoc: vi.fn(),
|
|
storeCompiledDoc: vi.fn(),
|
|
}))
|
|
|
|
import { collectReferencedFileIds } from './doc-compile'
|
|
|
|
const ID = '550e8400-e29b-41d4-a716-446655440000'
|
|
|
|
describe('collectReferencedFileIds', () => {
|
|
it('captures the id from getFileBase64(...) with single or double quotes', () => {
|
|
expect(collectReferencedFileIds(`await getFileBase64('${ID}')`)).toEqual(new Set([ID]))
|
|
expect(collectReferencedFileIds(`getFileBase64("abc_def-1")`)).toEqual(new Set(['abc_def-1']))
|
|
})
|
|
|
|
it('captures the id from pptx addImage(slide, id, opts) (second arg)', () => {
|
|
const src = `await addImage(slide, '${ID}', { x: 1, y: 1, w: 2, h: 2 })`
|
|
expect(collectReferencedFileIds(src)).toEqual(new Set([ID]))
|
|
})
|
|
|
|
it('captures the id from docx addImage(id, opts) (first arg)', () => {
|
|
const src = `const img = await addImage('docx-img-1', { width: 200, height: 100 })`
|
|
expect(collectReferencedFileIds(src)).toEqual(new Set(['docx-img-1']))
|
|
})
|
|
|
|
it('captures the id from pdf drawImage(page, id, opts) (second arg)', () => {
|
|
const src = `await drawImage(page, 'pdf-img-2', { x: 0, y: 0, width: 100, height: 100 })`
|
|
expect(collectReferencedFileIds(src)).toEqual(new Set(['pdf-img-2']))
|
|
})
|
|
|
|
it('still supports the legacy /home/user/inputs/<id> path form', () => {
|
|
expect(collectReferencedFileIds(`fs.readFileSync('/home/user/inputs/legacy-1')`)).toEqual(
|
|
new Set(['legacy-1'])
|
|
)
|
|
})
|
|
|
|
it('collects and dedupes ids across multiple call sites', () => {
|
|
const src = `
|
|
await addImage(slide, 'logo-1', { x: 0, y: 0, w: 1, h: 1 });
|
|
const uri = await getFileBase64('logo-1');
|
|
await addImage(slide, 'crest-2', { x: 2, y: 0, w: 1, h: 1 });
|
|
`
|
|
expect(collectReferencedFileIds(src)).toEqual(new Set(['logo-1', 'crest-2']))
|
|
})
|
|
|
|
it('does not match id-like strings outside the image helpers', () => {
|
|
const src = `slide.addText('order ${ID} shipped', { x: 1, y: 1, w: 8, h: 1 })`
|
|
expect(collectReferencedFileIds(src)).toEqual(new Set())
|
|
})
|
|
|
|
it('does not match slide.addImage({ data }) — no fileId is present there', () => {
|
|
const src = `slide.addImage({ data: base64Data, x: 1, y: 1, w: 2, h: 2 })`
|
|
expect(collectReferencedFileIds(src)).toEqual(new Set())
|
|
})
|
|
|
|
it('returns an empty set when there are no image references', () => {
|
|
expect(collectReferencedFileIds(`slide.addText('hello', { x: 1, y: 1 })`)).toEqual(new Set())
|
|
})
|
|
})
|