Skip to content

Commit 46eef76

Browse files
committed
fix(files): align search with rendered cache identities
1 parent dcea25c commit 46eef76

4 files changed

Lines changed: 63 additions & 14 deletions

File tree

‎apps/sim/lib/projects/files/__integration__/content-rendered.integration.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,8 @@ afterAll(async () => {
855855
}
856856
await rm(localStorageRoot, { recursive: true, force: true })
857857
const report =
858-
process.env.PROJECT_FILE_CONTENT_REPORT_PATH ?? 'test-results/project-file-content.json'
858+
process.env.PROJECT_FILE_RENDERED_CONTENT_REPORT_PATH ??
859+
'test-results/project-file-rendered-content.json'
859860
await mkdir(dirname(report), { recursive: true })
860861
await writeFile(report, JSON.stringify({ checks }, null, 2))
861862
await db.$client.end()

‎apps/sim/lib/uploads/documents/compile.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,21 @@ async function renderPreparedDocument(source: string, fmt: E2BDocFormat, inputs:
620620
: compileDocViaE2BPython(source, fmt, inputs)
621621
}
622622

623+
/** Shared identity for owner-bound rendering and readers of its compiled artifacts. */
624+
export function fileDocumentCacheIdentity(
625+
source: string,
626+
format: E2BDocFormat,
627+
sourceMime: string,
628+
inputIdentity?: string
629+
): string {
630+
return JSON.stringify({
631+
sourceLanguage: getDocumentSourceLanguage(source, format, sourceMime),
632+
renderer:
633+
isDocSandboxEnabled && sourceMime !== 'text/x-pdflibjs' ? 'document-sandbox' : 'native',
634+
inputs: inputIdentity ?? null,
635+
})
636+
}
637+
623638
/** Compiles a document against a fixed, authorized input manifest and canonical owner cache. */
624639
export async function compileFileDocument(args: {
625640
owner: EditableFileOwner
@@ -641,11 +656,12 @@ export async function compileFileDocument(args: {
641656
throw new DocCompileUserError('Document inputs exceed the rendering limit')
642657
}
643658
const useDocumentSandbox = isDocSandboxEnabled && args.sourceMime !== 'text/x-pdflibjs'
644-
const cacheIdentity = JSON.stringify({
645-
sourceLanguage: getDocumentSourceLanguage(args.source, fmt, args.sourceMime),
646-
renderer: useDocumentSandbox ? 'document-sandbox' : 'native',
647-
inputs: args.inputIdentity ?? null,
648-
})
659+
const cacheIdentity = fileDocumentCacheIdentity(
660+
args.source,
661+
fmt,
662+
args.sourceMime,
663+
args.inputIdentity
664+
)
649665
const cached = await loadCompiledDoc(args.owner, args.source, fmt.ext, cacheIdentity, {
650666
maxBytes: args.maxBytes,
651667
signal: args.signal,

‎apps/sim/lib/workspace-files/search/owners.integration.ts‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
createOwnedWorkspaceFile,
5454
uploadWorkspaceFile,
5555
} from '@/lib/uploads/contexts/workspace/file-manager'
56+
import { fileDocumentCacheIdentity, getE2BDocFormat } from '@/lib/uploads/documents/compile'
5657
import { compiledArtifactKey, storeCompiledDoc } from '@/lib/uploads/documents/compiled-store'
5758
import { fileDocumentInputIdentity } from '@/lib/uploads/documents/input-identity'
5859
import { deleteUserAccount } from '@/lib/users/account-deletion'
@@ -773,7 +774,12 @@ describe('owner-scoped indexed file search on PostgreSQL and stored bytes', () =
773774
'docx',
774775
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
775776
artifact,
776-
fileDocumentInputIdentity(f.owner, [dependencyRow])
777+
fileDocumentCacheIdentity(
778+
source,
779+
(await getE2BDocFormat('report.docx'))!,
780+
'text/plain',
781+
fileDocumentInputIdentity(f.owner, [dependencyRow])
782+
)
777783
)
778784
const { loadFileSearchSource } = await import('@/lib/workspace-files/search/source')
779785
const revision = {
@@ -866,7 +872,8 @@ describe('owner-scoped indexed file search on PostgreSQL and stored bytes', () =
866872
source,
867873
'docx',
868874
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
869-
artifact
875+
artifact,
876+
fileDocumentCacheIdentity(source, (await getE2BDocFormat('transition.docx'))!, 'text/plain')
870877
)
871878
const input = { projectId: f.projectId, fileId: generated.file.id, maxBytes: 1_000_000 }
872879
const rendered = await readProjectFileArtifact.execute({ principal: f.reader, input })
@@ -987,13 +994,23 @@ describe('owner-scoped indexed file search on PostgreSQL and stored bytes', () =
987994
await Packer.toBuffer(
988995
new Document({ sections: [{ children: [new Paragraph('oldrender')] }] })
989996
),
990-
fileDocumentInputIdentity(f.owner, [dependencyRow])
997+
fileDocumentCacheIdentity(
998+
source,
999+
(await getE2BDocFormat('report.docx'))!,
1000+
'text/plain',
1001+
fileDocumentInputIdentity(f.owner, [dependencyRow])
1002+
)
9911003
)
9921004
const artifactKey = compiledArtifactKey(
9931005
f.owner,
9941006
source,
9951007
'docx',
996-
fileDocumentInputIdentity(f.owner, [dependencyRow])
1008+
fileDocumentCacheIdentity(
1009+
source,
1010+
(await getE2BDocFormat('report.docx'))!,
1011+
'text/plain',
1012+
fileDocumentInputIdentity(f.owner, [dependencyRow])
1013+
)
9971014
)
9981015
const completion = {
9991016
owner: f.owner,
@@ -1070,13 +1087,23 @@ describe('owner-scoped indexed file search on PostgreSQL and stored bytes', () =
10701087
await Packer.toBuffer(
10711088
new Document({ sections: [{ children: [new Paragraph('old-contributor')] }] })
10721089
),
1073-
fileDocumentInputIdentity(f.owner, [dependencyRow])
1090+
fileDocumentCacheIdentity(
1091+
source,
1092+
(await getE2BDocFormat('report.docx'))!,
1093+
'text/plain',
1094+
fileDocumentInputIdentity(f.owner, [dependencyRow])
1095+
)
10741096
)
10751097
const artifactKey = compiledArtifactKey(
10761098
f.owner,
10771099
source,
10781100
'docx',
1079-
fileDocumentInputIdentity(f.owner, [dependencyRow])
1101+
fileDocumentCacheIdentity(
1102+
source,
1103+
(await getE2BDocFormat('report.docx'))!,
1104+
'text/plain',
1105+
fileDocumentInputIdentity(f.owner, [dependencyRow])
1106+
)
10801107
)
10811108
const { markFileSearchArtifactReadyInTx } = await import(
10821109
'@/lib/workspace-files/search/artifact-ready'

‎apps/sim/lib/workspace-files/search/source.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
getE2BDocFormat,
1111
isCompiledDocumentBuffer,
1212
} from '@/lib/uploads/documents'
13+
import { fileDocumentCacheIdentity } from '@/lib/uploads/documents/compile'
1314
import { DocCompileUserError } from '@/lib/uploads/documents/compile-error'
1415
import { compiledArtifactKey, loadCompiledDoc } from '@/lib/uploads/documents/compiled-store'
1516
import { fileDocumentInputIdentity } from '@/lib/uploads/documents/input-identity'
@@ -102,7 +103,11 @@ export async function loadFileSearchSource(
102103
if (inputs.length !== ids.length) throw new FileSearchExclusionError('incomplete_extraction')
103104
signal.throwIfAborted()
104105
const inputIdentity = fileDocumentInputIdentity(owner, inputs)
105-
const artifact = await loadCompiledDoc(owner, source, format.ext, inputIdentity, {
106+
const cacheIdentity =
107+
owner.entityType === 'project'
108+
? fileDocumentCacheIdentity(source, format, file.contentType, inputIdentity)
109+
: inputIdentity
110+
const artifact = await loadCompiledDoc(owner, source, format.ext, cacheIdentity, {
106111
maxBytes: FILE_SEARCH_MAX_SOURCE_BYTES,
107112
signal,
108113
})
@@ -111,7 +116,7 @@ export async function loadFileSearchSource(
111116
bytes: artifact ? { buffer: artifact, kind: 'artifact' } : { buffer: raw, kind: 'source' },
112117
...(artifact
113118
? {
114-
artifactKey: compiledArtifactKey(owner, source, format.ext, inputIdentity),
119+
artifactKey: compiledArtifactKey(owner, source, format.ext, cacheIdentity),
115120
}
116121
: {}),
117122
dependencies: inputs.map((input) => ({

0 commit comments

Comments
 (0)