Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(upload): import Office folders, legacy Office files and .xlsm (#7594)
Jacob Beckerman632b2ef44bbc
diff --git a/.github/workspace-dep-closures.json b/.github/workspace-dep-closures.jsonindex f2ff67c96f..3a2122f727 100644--- a/.github/workspace-dep-closures.json+++ b/.github/workspace-dep-closures.json@@ -4877,6 +4877,7 @@"crates/macro_env_var","crates/macro_event_broker","crates/macro_event_topics",+ "crates/macro_queues","crates/macro_service_urls","crates/macro_sync_service_jwt","crates/macro_tower_layers",diff --git a/.sqlx/query-1f21761b4bc48d82468fa7e8cebbd5e309aab299895ab0e4a91c01a870d9109c.json b/.sqlx/query-1f21761b4bc48d82468fa7e8cebbd5e309aab299895ab0e4a91c01a870d9109c.jsonnew file mode 100644index 0000000000..1b5d58ed19--- /dev/null+++ b/.sqlx/query-1f21761b4bc48d82468fa7e8cebbd5e309aab299895ab0e4a91c01a870d9109c.json@@ -0,0 +1,16 @@+{+ "db_name": "PostgreSQL",+ "query": "\n UPDATE \"Document\"\n SET \"fileType\" = $3,\n \"updatedAt\" = NOW()\n WHERE id = $1 AND LOWER(\"fileType\") = $2\n ",+ "describe": {+ "columns": [],+ "parameters": {+ "Left": [+ "Text",+ "Text",+ "Text"+ ]+ },+ "nullable": []+ },+ "hash": "1f21761b4bc48d82468fa7e8cebbd5e309aab299895ab0e4a91c01a870d9109c"+}diff --git a/.sqlx/query-3f6fad37bbed718a3124a1946c642b63e816133ecea6ce72c8c9507277617f30.json b/.sqlx/query-3f6fad37bbed718a3124a1946c642b63e816133ecea6ce72c8c9507277617f30.jsonnew file mode 100644index 0000000000..585499ecb1--- /dev/null+++ b/.sqlx/query-3f6fad37bbed718a3124a1946c642b63e816133ecea6ce72c8c9507277617f30.json@@ -0,0 +1,22 @@+{+ "db_name": "PostgreSQL",+ "query": "\n INSERT INTO \"DocumentBom\" (\"documentId\", \"createdAt\", \"updatedAt\")\n VALUES ($1, NOW(), NOW())\n RETURNING id\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Int8"+ }+ ],+ "parameters": {+ "Left": [+ "Text"+ ]+ },+ "nullable": [+ false+ ]+ },+ "hash": "3f6fad37bbed718a3124a1946c642b63e816133ecea6ce72c8c9507277617f30"+}diff --git a/.sqlx/query-92d93a6bc6a48cce58a03908a840395eb184c9eb259894f689390b13e5647a6c.json b/.sqlx/query-92d93a6bc6a48cce58a03908a840395eb184c9eb259894f689390b13e5647a6c.jsonnew file mode 100644index 0000000000..c8b812d456--- /dev/null+++ b/.sqlx/query-92d93a6bc6a48cce58a03908a840395eb184c9eb259894f689390b13e5647a6c.json@@ -0,0 +1,14 @@+{+ "db_name": "PostgreSQL",+ "query": "DELETE FROM \"DocumentInstance\" WHERE id = $1",+ "describe": {+ "columns": [],+ "parameters": {+ "Left": [+ "Int8"+ ]+ },+ "nullable": []+ },+ "hash": "92d93a6bc6a48cce58a03908a840395eb184c9eb259894f689390b13e5647a6c"+}diff --git a/.sqlx/query-dadea3eca110a122079f319ea9d944cdab75327b002a16e85cf9da6fe8f18c8c.json b/.sqlx/query-dadea3eca110a122079f319ea9d944cdab75327b002a16e85cf9da6fe8f18c8c.jsonnew file mode 100644index 0000000000..ee430a934f--- /dev/null+++ b/.sqlx/query-dadea3eca110a122079f319ea9d944cdab75327b002a16e85cf9da6fe8f18c8c.json@@ -0,0 +1,14 @@+{+ "db_name": "PostgreSQL",+ "query": "DELETE FROM \"DocumentBom\" WHERE id = $1",+ "describe": {+ "columns": [],+ "parameters": {+ "Left": [+ "Int8"+ ]+ },+ "nullable": []+ },+ "hash": "dadea3eca110a122079f319ea9d944cdab75327b002a16e85cf9da6fe8f18c8c"+}diff --git a/.sqlx/query-e53dd219e78de6f92272433200e09f2d94ad20d9f6e193e1e92655d335a128d3.json b/.sqlx/query-e53dd219e78de6f92272433200e09f2d94ad20d9f6e193e1e92655d335a128d3.jsonnew file mode 100644index 0000000000..208428c261--- /dev/null+++ b/.sqlx/query-e53dd219e78de6f92272433200e09f2d94ad20d9f6e193e1e92655d335a128d3.json@@ -0,0 +1,23 @@+{+ "db_name": "PostgreSQL",+ "query": "\n INSERT INTO \"DocumentInstance\" (\"documentId\", \"sha\", \"createdAt\", \"updatedAt\")\n VALUES ($1, $2, NOW(), NOW())\n RETURNING id\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Int8"+ }+ ],+ "parameters": {+ "Left": [+ "Text",+ "Text"+ ]+ },+ "nullable": [+ false+ ]+ },+ "hash": "e53dd219e78de6f92272433200e09f2d94ad20d9f6e193e1e92655d335a128d3"+}diff --git a/Cargo.lock b/Cargo.lockindex 2d60478b4e..8399eb2cd4 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4805,6 +4805,7 @@ dependencies = ["aws-sdk-sqs","axum","database_env_vars",+ "docx_engine","doppler-config","futures","http-body-util",@@ -4823,6 +4824,7 @@ dependencies = ["macro_uuid","model","nix 0.29.0",+ "pptx_engine","remote_env_var","rs-libreoffice-bindings","s3_client",@@ -4833,6 +4835,7 @@ dependencies = ["sqlx","sqs_client","sqs_worker",+ "tempfile","tokio","tower 0.5.3","tower-http",@@ -6400,12 +6403,17 @@ dependencies = ["macro_aws_config","macro_entrypoint","macro_env_var",+ "macro_queues","macro_service_urls",+ "macro_uuid","model",+ "model_owner","s3_key","serde","serde_json",+ "sha2 0.10.9","sqlx",+ "sqs_client","sync_service_client","tokio","tracing",diff --git a/apps/web/scripts/agent-fold.test.ts b/apps/web/scripts/agent-fold.test.tsindex 36fa371e75..e85964654a 100644--- a/apps/web/scripts/agent-fold.test.ts+++ b/apps/web/scripts/agent-fold.test.ts@@ -18,7 +18,9 @@ beforeAll(async () => {module_or_path: readFileSync(new URL('agent_fold_bg.wasm', path)),});Stream = wasm.FoldStream;-}, 300_000);+ // CI compiles the release WASM from scratch on every run, which takes 3–6+ // minutes depending on the runner.+}, 600_000);it('decodes durable DTOs, reconciles overlap, and folds a batch like a stream', () => {const session = '00000000-0000-0000-0000-00000000000a';diff --git a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.tsindex 87e7e572ba..6a17d7f5ae 100644--- a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts+++ b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.browser.e2e.ts@@ -328,6 +328,71 @@ test('imports independent XLSX through the file picker and exports real formulas});});+test('imports a macro-enabled .xlsm without its macros and exports a macro-free .xlsx', async ({+ page,+}) => {+ const chooser = page.waitForEvent('filechooser');+ await menu(page, 'Import and export', 'Import…');+ await (await chooser).setFiles(+ fileURLToPath(+ new URL('../core/xlsx-fixtures/poi-simple-macro.xlsm', import.meta.url)+ )+ );+ const dialog = page.getByRole('dialog', { name: 'Import Excel workbook' });+ await expect(dialog).toBeVisible();+ await expect(dialog).toContainText('VBA macros are not imported.');+ await page.getByRole('radio', { name: /Replace workbook/ }).check();+ await page.getByRole('button', { name: 'Import workbook' }).click();+ await expect(page.getByRole('tab')).toHaveCount(3);+ await expect(page.locator('[data-address="A1"]')).toHaveText(+ 'This is a macro workbook'+ );++ const downloaded = page.waitForEvent('download');+ await menu(page, 'Import and export', 'Download as Excel (.xlsx)');+ const download = await downloaded;+ expect(download.suggestedFilename()).toBe('Spreadsheet fixture.xlsx');+ const path = await download.path();+ if (!path) throw new Error('The workbook download was not saved.');+ const workbook = new ExcelJS.Workbook();+ await workbook.xlsx.readFile(path);+ expect(workbook.worksheets.map((sheet) => sheet.name)).toEqual([+ 'Sheet1',+ 'Sheet2',+ 'Sheet3',+ ]);+ expect(workbook.getWorksheet('Sheet1')?.getCell('A1').value).toBe(+ 'This is a macro workbook'+ );+ const { unzipSync } = await import('fflate');+ const { readFileSync } = await import('node:fs');+ expect(+ Object.keys(unzipSync(readFileSync(path))).filter((name) =>+ /vba/i.test(name)+ )+ ).toEqual([]);+});++test('explains that legacy .xls workbooks convert when uploaded', async ({+ page,+}) => {+ const chooser = page.waitForEvent('filechooser');+ await menu(page, 'Import and export', 'Import…');+ await (await chooser).setFiles({+ name: 'budget.xls',+ mimeType: 'application/vnd.ms-excel',+ buffer: Buffer.from([0xd0, 0xcf, 0x11, 0xe0]),+ });+ await expect(+ page.getByText(+ 'Legacy .xls workbooks are converted when uploaded. Upload the file, then choose Edit in Macro.'+ )+ ).toBeVisible();+ await expect(+ page.getByRole('dialog', { name: 'Import Excel workbook' })+ ).toHaveCount(0);+});+test('undo restores the original workbook after replacing it with an Excel import', async ({page,}) => {diff --git a/apps/web/src/features/block-spreadsheet/core/csv-file.test.ts b/apps/web/src/features/block-spreadsheet/core/csv-file.test.tsindex 8714b1424d..9253694e95 100644--- a/apps/web/src/features/block-spreadsheet/core/csv-file.test.ts+++ b/apps/web/src/features/block-spreadsheet/core/csv-file.test.ts@@ -4,10 +4,11 @@ import { csvImportEdits } from './sheet-operations';import { decodeCsv, isUploadedWorkbook } from './uploaded-workbook';describe('uploaded Excel/CSV detection', () => {- it.each(['xlsx', 'XLSX', 'csv', 'CSV'])('recognizes %s', (type) =>- expect(isUploadedWorkbook(type)).toBe(true)+ it.each(['xlsx', 'XLSX', 'xlsm', 'XLSM', 'csv', 'CSV'])(+ 'recognizes %s',+ (type) => expect(isUploadedWorkbook(type)).toBe(true));- it.each(['xls', 'xlsm', 'pdf', 'spreadsheet', '', null, undefined])(+ it.each(['xls', 'xltm', 'pdf', 'spreadsheet', '', null, undefined])('rejects %s',(type) => expect(isUploadedWorkbook(type)).toBe(false));diff --git a/apps/web/src/features/block-spreadsheet/core/uploaded-workbook.ts b/apps/web/src/features/block-spreadsheet/core/uploaded-workbook.tsindex df0551bb3d..bbee229b5d 100644--- a/apps/web/src/features/block-spreadsheet/core/uploaded-workbook.ts+++ b/apps/web/src/features/block-spreadsheet/core/uploaded-workbook.ts@@ -6,7 +6,7 @@ import {import type { WorkbookFileData } from './workbook-file-types';export function isUploadedWorkbook(fileType: string | null | undefined) {- return /^(xlsx|csv)$/i.test(fileType ?? '');+ return /^(xlsx|xlsm|csv)$/i.test(fileType ?? '');}/** CSV carries values, not executable formulas or cell types. Keep identifiersdiff --git a/apps/web/src/features/block-spreadsheet/core/xlsm-import.test.ts b/apps/web/src/features/block-spreadsheet/core/xlsm-import.test.tsnew file mode 100644index 0000000000..f40600c7f4--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/core/xlsm-import.test.ts@@ -0,0 +1,220 @@+import { readFileSync } from 'node:fs';+import { createRequire } from 'node:module';+import { initSync } from '@ironcalc/wasm';+import { createInitializedSpreadsheetCalculator } from '@macro-inc/spreadsheet/calculation';+import {+ importSpreadsheetSheets,+ readSpreadsheetWorkbook,+} from '@macro-inc/spreadsheet/workbook-document';+import ExcelJS from 'exceljs';+import { strFromU8, strToU8, unzipSync, zipSync } from 'fflate';+import { LoroDoc } from 'loro-crdt';+import { beforeAll, describe, expect, it } from 'vitest';+import type { WorkbookFileSheet } from './workbook-file-types';+import { inspectXlsxArchive } from './xlsx-archive';+import { decodeXlsx, encodeXlsx } from './xlsx-codec';++const VBA_WARNING =+ 'VBA macros are not imported. Cells, formulas and formatting are; the macros do not run in Macro.';+const MACRO_SHEET_WARNING = 'Excel 4.0 macro sheets are not imported.';+const CONTROLS_WARNING = 'Form and ActiveX controls are not imported.';++const fixture = (name: string) =>+ new Uint8Array(+ readFileSync(+ createRequire(import.meta.url).resolve(`./xlsx-fixtures/${name}`)+ )+ );++beforeAll(() =>+ initSync({+ module: readFileSync(+ createRequire(import.meta.url).resolve('@ironcalc/wasm/wasm_bg.wasm')+ ),+ })+);++function budgetSheet(): WorkbookFileSheet {+ return {+ name: 'Budget',+ cells: {+ A1: { value: 'Item', bold: true },+ B1: { value: 'Amount', bold: true },+ A2: { value: 'Rent' },+ B2: { value: '1200' },+ A3: { value: 'Payroll' },+ B3: { value: '4800' },+ A4: { value: 'Total' },+ B4: { value: '=SUM(B2:B3)' },+ },+ rowCount: 100,+ columnWidths: {},+ };+}++/**+ * A Macro-written workbook turned into the package Excel saves as .xlsm: the+ * macro-enabled main content type, a VBA project and its signature, plus any+ * `extra` parts.+ */+async function macroEnabled(extra: Record<string, Uint8Array> = {}) {+ const { bytes } = await encodeXlsx({ sheets: [budgetSheet()] });+ const entries = unzipSync(bytes);+ entries['[Content_Types].xml'] = strToU8(+ strFromU8(entries['[Content_Types].xml'])+ .replace(+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml',+ 'application/vnd.ms-excel.sheet.macroEnabled.main+xml'+ )+ .replace(+ '</Types>',+ '<Default Extension="bin" ContentType="application/vnd.ms-office.vbaProject"/></Types>'+ )+ );+ entries['xl/_rels/workbook.xml.rels'] = strToU8(+ strFromU8(entries['xl/_rels/workbook.xml.rels']).replace(+ '</Relationships>',+ '<Relationship Id="rIdVba" Type="http://schemas.microsoft.com/office/2006/relationships/vbaProject" Target="vbaProject.bin"/></Relationships>'+ )+ );+ // An OLE compound file header; the importer never reads the VBA project.+ entries['xl/vbaProject.bin'] = new Uint8Array([+ 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1,+ ]);+ entries['xl/vbaProjectSignature.bin'] = new Uint8Array([1, 2, 3]);+ Object.assign(entries, extra);+ return zipSync(entries);+}++async function exportedParts(sheets: WorkbookFileSheet[]) {+ const { bytes } = await encodeXlsx({ sheets });+ return { bytes, names: Object.keys(unzipSync(bytes)) };+}++describe('macro-enabled workbook import', () => {+ it('imports a macro-enabled workbook with its formulas and a note about the macros', async () => {+ const imported = await decodeXlsx(await macroEnabled());++ expect(imported.sheets.map((sheet) => sheet.name)).toEqual(['Budget']);+ expect(imported.sheets[0].cells.A4.value).toBe('Total');+ expect(imported.sheets[0].cells.B4.value).toBe('=SUM(B2:B3)');+ expect(imported.sheets[0].cells.A1.bold).toBe(true);+ expect(imported.warnings).toContain(VBA_WARNING);+ expect(imported.warnings).not.toContain(MACRO_SHEET_WARNING);+ expect(imported.warnings).not.toContain(CONTROLS_WARNING);+ });++ it('notes Excel 4.0 macro sheets and form controls separately', async () => {+ const imported = await decodeXlsx(+ await macroEnabled({+ 'xl/macrosheets/sheet2.xml': strToU8(+ '<xm:macrosheet xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main"/>'+ ),+ 'xl/activeX/activeX1.xml': strToU8('<ax:ocx xmlns:ax="urn:ax"/>'),+ 'xl/ctrlProps/ctrlProp1.xml': strToU8('<formControlPr/>'),+ })+ );++ expect(imported.warnings).toEqual(+ expect.arrayContaining([+ VBA_WARNING,+ MACRO_SHEET_WARNING,+ CONTROLS_WARNING,+ ])+ );+ expect(imported.sheets[0].cells.B4.value).toBe('=SUM(B2:B3)');+ });++ it('calculates an imported macro-enabled workbook after native save and reopen', async () => {+ const imported = await decodeXlsx(await macroEnabled());+ const doc = new LoroDoc();+ const reopened = new LoroDoc();+ const engine = createInitializedSpreadsheetCalculator();+ try {+ importSpreadsheetSheets(doc, imported.sheets, true);+ reopened.import(doc.export({ mode: 'snapshot' }));+ const sheets = readSpreadsheetWorkbook(reopened);+ const results = engine.calculateWorkbook(+ sheets.map((sheet) => ({ ...sheet, rowCount: sheet.layout.rowCount })),+ { includeTypes: true }+ );+ expect(results[sheets[0].id].B4.number).toBe(6_000);+ } finally {+ engine.dispose();+ }+ });++ it('exports an imported macro-enabled workbook as a macro-free .xlsx', async () => {+ const imported = await decodeXlsx(await macroEnabled());++ const { bytes, names } = await exportedParts(imported.sheets);++ expect(names.some((name) => /vba|macrosheets|activeX/i.test(name))).toBe(+ false+ );+ const contentTypes = strFromU8(unzipSync(bytes)['[Content_Types].xml']);+ expect(contentTypes).toContain(+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml'+ );+ expect(contentTypes).not.toContain('macroEnabled');+ const external = new ExcelJS.Workbook();+ await external.xlsx.load(bytes.slice().buffer);+ expect(external.getWorksheet('Budget')!.getCell('B4').formula).toBe(+ 'SUM(B2:B3)'+ );+ });++ it("still refuses macros in Macro's own export check", async () => {+ expect(() => inspectXlsxArchive(fixture('poi-simple-macro.xlsm'))).toThrow(+ 'must not contain macros'+ );+ expect(() =>+ inspectXlsxArchive(+ zipSync({+ ...unzipSync(fixture('poi-simple-macro.xlsm')),+ 'xl/vbaProject.bin': new Uint8Array(),+ })+ )+ ).toThrow('must not contain macros');+ });+});++describe('Excel-written .xlsm files', () => {+ it('imports a simple macro workbook', async () => {+ const imported = await decodeXlsx(fixture('poi-simple-macro.xlsm'));++ expect(imported.sheets.map((sheet) => sheet.name)).toEqual([+ 'Sheet1',+ 'Sheet2',+ 'Sheet3',+ ]);+ expect(imported.sheets[0].cells.A1.value).toBe('This is a macro workbook');+ expect(imported.warnings).toContain(VBA_WARNING);++ const { names } = await exportedParts(imported.sheets);+ expect(names).not.toContain('xl/vbaProject.bin');+ });++ it('imports a macro workbook with comments, embedded objects and Cyrillic sheet names', async () => {+ const imported = await decodeXlsx(+ fixture('poi-excel-with-attachments.xlsm')+ );++ expect(imported.sheets.map((sheet) => sheet.name)).toEqual([+ 'Страница 1',+ 'Page 1',+ 'Бетўўў 1',+ ]);+ const text = imported.sheets.flatMap((sheet) =>+ Object.values(sheet.cells).map((cell) => cell.value)+ );+ expect(text).toEqual(+ expect.arrayContaining(['Русский вариант', 'English', 'Ўзбек'])+ );+ expect(imported.warnings).toContain(VBA_WARNING);++ const { bytes, names } = await exportedParts(imported.sheets);+ expect(names.some((name) => /vbaProject/i.test(name))).toBe(false);+ expect(() => inspectXlsxArchive(bytes)).not.toThrow();+ });+});diff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-archive.ts b/apps/web/src/features/block-spreadsheet/core/xlsx-archive.tsindex 77d7d58029..5e068fade9 100644--- a/apps/web/src/features/block-spreadsheet/core/xlsx-archive.ts+++ b/apps/web/src/features/block-spreadsheet/core/xlsx-archive.ts@@ -29,7 +29,10 @@ type ArchiveEntry = {};/** Validate the ZIP directory: bounded, unencrypted, no path aliases. */-function archiveEntries(bytes: Uint8Array): {+function archiveEntries(+ bytes: Uint8Array,+ { allowMacros }: { allowMacros: boolean }+): {entries: ArchiveEntry[];centralStart: number;} {@@ -115,10 +118,10 @@ function archiveEntries(bytes: Uint8Array): {!names.has('xl/workbook.xml'))throw invalid();- if ([...names].some((name) => /vbaProject\.bin$/i.test(name)))- throw new Error(- 'Macro-enabled workbooks are not supported. Save a macro-free .xlsx copy first.'- );+ // Imports drop macros with a warning; Macro's own exports must never+ // contain them.+ if (!allowMacros && [...names].some(isMacroPart))+ throw new Error('Workbooks written by Macro must not contain macros.');return { entries, centralStart };}@@ -159,7 +162,9 @@ function inflateEntry(/** Validate ZIP metadata and inflate every entry into fixed buffers. */export function inspectXlsxArchive(bytes: Uint8Array) {- const { entries, centralStart } = archiveEntries(bytes);+ const { entries, centralStart } = archiveEntries(bytes, {+ allowMacros: false,+ });const files: Record<string, Uint8Array> = Object.create(null);for (const entry of entries)files[entry.name] = inflateEntry(bytes, entry, centralStart);@@ -174,7 +179,9 @@ export type XlsxArchive = {/** Validate the directory up front, then inflate entries only when read. */export function openXlsxArchive(bytes: Uint8Array): XlsxArchive {- const { entries, centralStart } = archiveEntries(bytes);+ const { entries, centralStart } = archiveEntries(bytes, {+ allowMacros: true,+ });const byName = new Map(entries.map((entry) => [entry.name, entry]));return {names: [...byName.keys()],@@ -185,6 +192,14 @@ export function openXlsxArchive(bytes: Uint8Array): XlsxArchive {};}+/** VBA projects, their signatures, and Excel 4.0 macro sheets. */+function isMacroPart(name: string) {+ return (+ /(^|\/)vbaProject(Signature(Agile|V3)?)?\.bin$/i.test(name) ||+ /^xl\/macrosheets\//i.test(name)+ );+}+/** Warnings for package parts Macro does not import, from entry names alone. */export function xlsxFeatureWarnings(names: string[]): string[] {const warnings = new Set<string>();@@ -197,6 +212,14 @@ export function xlsxFeatureWarnings(names: string[]): string[] {warnings.add('Excel tables are imported as ordinary cells; table formulas are converted to cell ranges.');+ if (/(^|\/)vbaProject\.bin$/i.test(name))+ warnings.add(+ 'VBA macros are not imported. Cells, formulas and formatting are; the macros do not run in Macro.'+ );+ if (/^xl\/macrosheets\//i.test(name))+ warnings.add('Excel 4.0 macro sheets are not imported.');+ if (/^xl\/(activeX|ctrlProps)\//i.test(name))+ warnings.add('Form and ActiveX controls are not imported.');}return [...warnings];}diff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-codec.test.ts b/apps/web/src/features/block-spreadsheet/core/xlsx-codec.test.tsindex ac5dbe0d03..71d0371049 100644--- a/apps/web/src/features/block-spreadsheet/core/xlsx-codec.test.ts+++ b/apps/web/src/features/block-spreadsheet/core/xlsx-codec.test.ts@@ -564,7 +564,7 @@ describe('Excel workbook files', () => {expect(result.rowCount).toBe(5000);});- it('rejects invalid ZIP, encryption, macros, corrupt data and forged expansion sizes', async () => {+ it('rejects invalid ZIP, encryption, exported macros, corrupt data and forged expansion sizes', async () => {await expect(decodeXlsx(new Uint8Array(XLSX_MAX_BYTES + 1))).rejects.toThrow('50 MB');@@ -574,7 +574,10 @@ describe('Excel workbook files', () => {const original = (await encodeXlsx({ sheets: [simpleSheet()] })).bytes;const entries = unzipSync(original);entries['xl/vbaProject.bin'] = new Uint8Array([1]);- await expect(decodeXlsx(zipSync(entries))).rejects.toThrow('Macro-enabled');+ // Imports drop macros (see xlsm-import.test.ts); exports may never carry them.+ expect(() => inspectXlsxArchive(zipSync(entries))).toThrow(+ 'must not contain macros'+ );const central = (bytes: Uint8Array) => {const view = new DataView(bytes.buffer,diff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/README.md b/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/README.mdindex d494582b0d..e763c1f2a9 100644--- a/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/README.md+++ b/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/README.md@@ -49,3 +49,7 @@ Notices:- U.S. federal works (SEC, Census, BLS, BEA, IRS, SBA, GSA) are in the public domain; the FRED export carries BLS series data.Templates whose terms forbid redistribution (Microsoft Create, Vertex42, Breaking Into Wall Street, Damodaran, SBDC) were used only for local testing and are not committed. Add a file by copying it here unmodified and adding its `file`, `title`, `source` and `license` to the manifest; set `skipCalculation` with a reason only when the engine cannot finish it.++`upgraded-from-xls.xlsx` is a legacy Excel 97 workbook (`services/convert_service/fixtures/legacy/budget.xls`) converted to `.xlsx` by LibreOffice with the `Calc MS Excel 2007 XML` filter, exactly as the convert service upgrades uploaded `.xls` files. `../xlsx-upgraded-legacy.test.ts` checks that it imports into a native spreadsheet with its sheets, formulas, merges and number formats.++`poi-simple-macro.xlsm` and `poi-excel-with-attachments.xlsm` are Excel-written macro-enabled workbooks with real VBA projects, from the Apache POI test data (`test-data/spreadsheet/SimpleMacro.xlsm` and `ExcelWithAttachments.xlsm` at https://github.com/apache/poi, Apache-2.0). The second also has comments, embedded Word and PowerPoint objects and Cyrillic sheet names. `../xlsm-import.test.ts` checks that both import with their macros dropped and export as macro-free `.xlsx`.diff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/poi-excel-with-attachments.xlsm b/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/poi-excel-with-attachments.xlsmnew file mode 100644index 0000000000..cb3e564428Binary files /dev/null and b/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/poi-excel-with-attachments.xlsm differdiff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/poi-simple-macro.xlsm b/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/poi-simple-macro.xlsmnew file mode 100644index 0000000000..ec64525bf8Binary files /dev/null and b/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/poi-simple-macro.xlsm differdiff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/upgraded-from-xls.xlsx b/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/upgraded-from-xls.xlsxnew file mode 100644index 0000000000..775d52de0aBinary files /dev/null and b/apps/web/src/features/block-spreadsheet/core/xlsx-fixtures/upgraded-from-xls.xlsx differdiff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-upgraded-legacy.test.ts b/apps/web/src/features/block-spreadsheet/core/xlsx-upgraded-legacy.test.tsnew file mode 100644index 0000000000..13f4282bac--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/core/xlsx-upgraded-legacy.test.ts@@ -0,0 +1,122 @@+import { readFileSync } from 'node:fs';+import { createRequire } from 'node:module';+import { initSync } from '@ironcalc/wasm';+import { createInitializedSpreadsheetCalculator } from '@macro-inc/spreadsheet/calculation';+import {+ importSpreadsheetSheets,+ readSpreadsheetWorkbook,+} from '@macro-inc/spreadsheet/workbook-document';+import ExcelJS from 'exceljs';+import { LoroDoc } from 'loro-crdt';+import { beforeAll, describe, expect, it } from 'vitest';+import { decodeXlsx, encodeXlsx } from './xlsx-codec';++/**+ * An uploaded legacy `.xls` is upgraded to `.xlsx` by LibreOffice on the+ * server; this is that output for a two-sheet budget. It must import into a+ * native spreadsheet like any Excel-written workbook.+ */+const upgraded = () =>+ new Uint8Array(+ readFileSync(+ createRequire(import.meta.url).resolve(+ './xlsx-fixtures/upgraded-from-xls.xlsx'+ )+ )+ );++beforeAll(() =>+ initSync({+ module: readFileSync(+ createRequire(import.meta.url).resolve('@ironcalc/wasm/wasm_bg.wasm')+ ),+ })+);++describe('workbook upgraded from a legacy .xls', () => {+ it('imports both sheets with their cells and formulas', async () => {+ const imported = await decodeXlsx(upgraded());++ expect(imported.sheets.map((sheet) => sheet.name)).toEqual([+ 'Budget',+ 'Notes',+ ]);+ const [budget, notes] = imported.sheets;+ expect(budget.cells.A1.value).toBe('Month');+ // Stored as text in the .xls, so it stays text rather than becoming a date.+ expect(budget.cells.A2.value).toBe("'2026-01");+ expect(budget.cells.B2.value).toBe('1050');+ expect(budget.cells.D2.value).toBe('=B2-C2');+ expect(budget.cells.D13.value).toBe('=B13-C13');+ expect(budget.cells.A15.value).toBe('Total');+ expect(budget.cells.B15.value).toBe('=SUM(B2:B13)');+ expect(budget.cells.D15.value).toBe('=SUM(D2:D13)');+ expect(budget.cells.F1.value).toBe('Merged header');+ expect(notes.cells.B1.value).toBe('Finance');+ expect(notes.cells.B2.value).toBe('=Budget!D15/Budget!B15');+ });++ it('keeps header styles, number formats and the merged header', async () => {+ const imported = await decodeXlsx(upgraded());+ const budget = imported.sheets[0];++ expect(budget.cells.A1).toMatchObject({+ bold: true,+ fillColor: '#DDEBF7',+ });+ // `#,##0.00` imports as Macro's thousands-separated number format.+ expect(budget.cells.B15).toMatchObject({ format: 'number', decimals: 2 });+ expect(budget.metadata?.merges).toEqual(['F1:H1']);+ expect(imported.warnings).toEqual([+ 'Merged ranges are shown as individual cells in Macro and restored on Excel export when their covered cells remain empty.',+ ]);+ });++ it('calculates the same results after native save and reopen', async () => {+ const imported = await decodeXlsx(upgraded());+ const doc = new LoroDoc();+ const reopened = new LoroDoc();+ const engine = createInitializedSpreadsheetCalculator();+ try {+ importSpreadsheetSheets(doc, imported.sheets, true);+ reopened.import(doc.export({ mode: 'snapshot' }));+ const sheets = readSpreadsheetWorkbook(reopened);+ const results = engine.calculateWorkbook(+ sheets.map((sheet) => ({ ...sheet, rowCount: sheet.layout.rowCount })),+ { includeTypes: true }+ );++ const budget = results[sheets[0].id];+ // Revenue 1000 + 50i and cost 600 + 20i for months 1..12.+ expect(budget.B15.number).toBe(15_900);+ expect(budget.C15.number).toBe(8_760);+ expect(budget.D15.number).toBe(7_140);+ expect(budget.D2.number).toBe(430);+ expect(budget.B15.display).toBe('15,900.00');+ expect(results[sheets[1].id].B2.number).toBeCloseTo(7_140 / 15_900, 12);+ for (const values of Object.values(results)) {+ expect(+ Object.entries(values).filter(([, value]) => value.error)+ ).toEqual([]);+ }+ } finally {+ engine.dispose();+ }+ });++ it('exports back to an .xlsx Excel reads with the same formulas', async () => {+ const imported = await decodeXlsx(upgraded());++ const exported = await encodeXlsx({ sheets: imported.sheets });++ const external = new ExcelJS.Workbook();+ await external.xlsx.load(exported.bytes.slice().buffer);+ const budget = external.getWorksheet('Budget')!;+ expect(budget.getCell('B15').formula).toBe('SUM(B2:B13)');+ expect(budget.getCell('D2').formula).toBe('B2-C2');+ expect(budget.getCell('F1').isMerged).toBe(true);+ expect(external.getWorksheet('Notes')!.getCell('B2').formula).toBe(+ 'Budget!D15/Budget!B15'+ );+ });+});diff --git a/apps/web/src/features/block-spreadsheet/primitives/create-workbook-actions.test.ts b/apps/web/src/features/block-spreadsheet/primitives/create-workbook-actions.test.tsindex 9ee0512e56..dc768e0cf0 100644--- a/apps/web/src/features/block-spreadsheet/primitives/create-workbook-actions.test.ts+++ b/apps/web/src/features/block-spreadsheet/primitives/create-workbook-actions.test.ts@@ -191,7 +191,7 @@ describe('workbook import and export actions', () => {it.each(['budget.xls',- 'budget.xlsm',+ 'budget.xltm','budget.xlsx.exe','budget.csv','budget',@@ -222,6 +222,24 @@ describe('workbook import and export actions', () => {expect(actions.notice()).toContain('50 MB');});+ it.each(['budget.xlsm', 'BUDGET.XLSM'])(+ 'previews macro-enabled workbook %s like an .xlsx',+ async (name) => {+ const { actions } = setup();+ vi.mocked(importWorkbookFile).mockResolvedValue({+ ...imported,+ warnings: ['VBA macros are not imported.'],+ });+ await actions.importExcel({ ...file, name });+ expect(importWorkbookFile).toHaveBeenCalled();+ expect(actions.preview()?.name).toBe(name);+ expect(actions.preview()?.data.warnings).toContain(+ 'VBA macros are not imported.'+ );+ expect(actions.notice()).toBe('');+ }+ );+it('replaces an old preview immediately and ignores stale decoder results from superseded requests', async () => {const { actions, store } = setup();vi.mocked(importWorkbookFile).mockResolvedValueOnce(imported);diff --git a/apps/web/src/features/block-spreadsheet/primitives/create-workbook-actions.ts b/apps/web/src/features/block-spreadsheet/primitives/create-workbook-actions.tsindex f8a5e44b5c..1672e267f6 100644--- a/apps/web/src/features/block-spreadsheet/primitives/create-workbook-actions.ts+++ b/apps/web/src/features/block-spreadsheet/primitives/create-workbook-actions.ts@@ -78,9 +78,9 @@ export function createWorkbookActions(options: {}async function importExcel(file: File) {if (!options.store.canEdit()) return;- if (!/\.xlsx$/i.test(file.name)) {+ if (!/\.xls[xm]$/i.test(file.name)) {setNotice(- 'Choose an .xlsx Excel workbook. Other file formats are not supported here.'+ 'Choose an .xlsx or .xlsm Excel workbook. Other file formats are not supported here.');return;}diff --git a/apps/web/src/features/block-spreadsheet/queries/uploaded-workbook.test.ts b/apps/web/src/features/block-spreadsheet/queries/uploaded-workbook.test.tsindex 555e9d8e9b..f2b09ea3a6 100644--- a/apps/web/src/features/block-spreadsheet/queries/uploaded-workbook.test.ts+++ b/apps/web/src/features/block-spreadsheet/queries/uploaded-workbook.test.ts@@ -32,6 +32,17 @@ describe('uploaded workbook retrieval', () => {expect(query().queryKey).not.toEqual(query('xlsx', 2).queryKey);expect(query().queryKey).not.toEqual(query('csv').queryKey);});+ it.each(['xlsm', 'XLSM'])(+ 'decodes a macro-enabled %s upload with the Excel worker',+ async (fileType) => {+ const signal = new AbortController().signal;+ vi.mocked(platformFetch).mockResolvedValueOnce(+ new Response(new Uint8Array([4, 5]))+ );+ await query(fileType).queryFn({ signal });+ expect(excel).toHaveBeenCalledWith(new Uint8Array([4, 5]), signal);+ }+ );it('opens CSV text as safe typed cells, without invoking the Excel worker', async () => {vi.mocked(platformFetch).mockResolvedValueOnce(new Response('ID,Amount\r\n00123,12.5')diff --git a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsxindex 42cdf952b1..ba01c68692 100644--- a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx+++ b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx@@ -529,13 +529,18 @@ export function SpreadsheetEditor(props: {async function importFile(file: File | undefined) {if (!file || !editable()) return;- if (!/\.(csv|xlsx)$/i.test(file.name)) {+ if (/\.xls$/i.test(file.name)) {+ // Converting .xls to .xlsx needs the server; uploads are upgraded.actions.setNotice(- 'Choose a .csv or .xlsx file. Legacy .xls and macro-enabled workbooks are not supported.'+ 'Legacy .xls workbooks are converted when uploaded. Upload the file, then choose Edit in Macro.');return;}- if (/\.xlsx$/i.test(file.name)) {+ if (!/\.(csv|xlsx|xlsm)$/i.test(file.name)) {+ actions.setNotice('Choose a .csv, .xlsx or .xlsm file.');+ return;+ }+ if (/\.xls[xm]$/i.test(file.name)) {await workbookActions.importExcel(file);return;}@@ -720,7 +725,7 @@ export function SpreadsheetEditor(props: {<inputref={importInput}type="file"- accept=".csv,.xlsx,text/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"+ accept=".csv,.xlsx,.xlsm,text/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel.sheet.macroEnabled.12"class="hidden"aria-label="Import spreadsheet file"onChange={(event) => {diff --git a/apps/web/src/features/block-unknown/component/Block.tsx b/apps/web/src/features/block-unknown/component/Block.tsxindex dc7355e4e4..897d74ae1f 100644--- a/apps/web/src/features/block-unknown/component/Block.tsx+++ b/apps/web/src/features/block-unknown/component/Block.tsx@@ -1,8 +1,10 @@import { FileSidePanelSections, SidePanel } from '@components/app/side-panel';+import { useSplitLayout } from '@components/app/split-layout/layout';import { useBlockId } from '@core/block';import { DocumentBlockContainer } from '@core/component/DocumentBlockContainer';import { toast } from '@core/component/Toast/Toast';import { useShareModal } from '@core/component/TopBar/shareModal';+import { fileTypeToBlockName } from '@core/constant/allBlocks';import { blockMetadataSignal } from '@core/signal/load';import { useGetPermissions } from '@core/signal/permissions';import {@@ -10,11 +12,26 @@ import {useBlockDocumentName,} from '@core/util/currentBlockDocumentName';import { downloadFile } from '@filesystem/download';+import { waitForDocumentContentReady } from '@queries/storage/document-location';+import { fetchDocumentMetadata } from '@queries/storage/document-metadata';import { createCallback } from '@solid-primitives/rootless';-import { lazy, Show, Suspense } from 'solid-js';+import {+ createSignal,+ lazy,+ onCleanup,+ onMount,+ Show,+ Suspense,+} from 'solid-js';import { SpreadsheetSkeleton } from '../../block-spreadsheet/components/SpreadsheetSkeleton';import { isUploadedWorkbook } from '../../block-spreadsheet/core/uploaded-workbook';import { useSpreadsheetAccess } from '../../block-spreadsheet/primitives/use-spreadsheet-access';+import {+ legacyOfficeUpgradeTarget,+ pollForLegacyUpgrade,+ shouldAwaitLegacyUpgrade,+ upgradedOfficeLabel,+} from '../legacy-office';import { useGetFileBlob } from '../signal/blockData';import { TopBar } from './TopBar';import { UnknownContent } from './UnknownContent';@@ -50,6 +67,7 @@ function BlockUnknownContent() {owner: blockMetadataSignal()?.owner,}));const getBlob = useGetFileBlob();+ const convertingTo = useLegacyOfficeUpgrade(blockId);const downloadDocument = createCallback(async () => {try {@@ -74,6 +92,7 @@ function BlockUnknownContent() {fallback={<UnknownContentfileName={fileName()}+ convertingTo={convertingTo()}onShare={openShare}onDownload={() => void downloadDocument()}/>@@ -88,3 +107,56 @@ function BlockUnknownContent() {</SidePanel.Layout>);}++/**+ * Waits for a just-uploaded .doc/.ppt/.xls to be upgraded to OpenXML, then+ * reopens it in the block for its new type. Returns the label of the format+ * being converted to while waiting.+ */+function useLegacyOfficeUpgrade(documentId: string) {+ const { replaceSplit } = useSplitLayout();+ const initial = blockMetadataSignal.get();+ const target = legacyOfficeUpgradeTarget(initial?.fileType);+ const [waiting, setWaiting] = createSignal(+ !!initial && !!target && shouldAwaitLegacyUpgrade(initial, Date.now())+ );++ onMount(() => {+ if (!target || !waiting()) return;+ const controller = new AbortController();+ onCleanup(() => controller.abort());++ void (async () => {+ const upgraded = await pollForLegacyUpgrade({+ target,+ fetchMetadata: () => fetchDocumentMetadata(documentId),+ fileTypeOf: (metadata) => metadata.fileType,+ sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),+ signal: controller.signal,+ });+ if (controller.signal.aborted) return;+ if (!upgraded) {+ setWaiting(false);+ return;+ }+ // Word content becomes readable once the DOCX pipeline processes it.+ if (target === 'docx') {+ await waitForDocumentContentReady({+ documentId,+ timeoutMs: 60_000,+ }).catch(() => undefined);+ if (controller.signal.aborted) return;+ }+ const blockName = fileTypeToBlockName(upgraded.fileType);+ if (blockName === 'unknown') {+ // Excel workbooks stay in this block, which previews them.+ blockMetadataSignal.set(upgraded);+ setWaiting(false);+ return;+ }+ replaceSplit({ content: { type: blockName, id: documentId } });+ })();+ });++ return () => (waiting() && target ? upgradedOfficeLabel(target) : undefined);+}diff --git a/apps/web/src/features/block-unknown/component/UnknownContent.test.tsx b/apps/web/src/features/block-unknown/component/UnknownContent.test.tsxnew file mode 100644index 0000000000..25d6483c16--- /dev/null+++ b/apps/web/src/features/block-unknown/component/UnknownContent.test.tsx@@ -0,0 +1,38 @@+import { cleanup, render, screen } from '@solidjs/testing-library';+import { afterEach, expect, it, vi } from 'vitest';+import { UnknownContent } from './UnknownContent';++afterEach(cleanup);++it('offers the file when there is no preview', () => {+ render(() => (+ <UnknownContent+ fileName="notes.bin"+ onShare={vi.fn()}+ onDownload={vi.fn()}+ />+ ));++ expect(screen.getByText(/No preview available for/)).toBeTruthy();+ expect(screen.queryByTestId('legacy-office-converting')).toBeNull();+ expect(screen.getByText('Download')).toBeTruthy();+});++it('says a legacy Office file is being converted and still offers the original', () => {+ const onDownload = vi.fn();+ render(() => (+ <UnknownContent+ fileName="Board Update.ppt"+ convertingTo="PowerPoint presentation"+ onShare={vi.fn()}+ onDownload={onDownload}+ />+ ));++ const status = screen.getByTestId('legacy-office-converting');+ expect(status.textContent).toContain('Board Update.ppt');+ expect(status.textContent).toContain('to a PowerPoint presentation');+ expect(screen.queryByText(/No preview available/)).toBeNull();+ screen.getByText('Download').click();+ expect(onDownload).toHaveBeenCalledOnce();+});diff --git a/apps/web/src/features/block-unknown/component/UnknownContent.tsx b/apps/web/src/features/block-unknown/component/UnknownContent.tsxindex 98c9ee2c75..64f44dfae2 100644--- a/apps/web/src/features/block-unknown/component/UnknownContent.tsx+++ b/apps/web/src/features/block-unknown/component/UnknownContent.tsx@@ -1,19 +1,41 @@+import { LoadingSpinner } from '@core/component/LoadingSpinner';import ShareFat from '@icon/share.svg';import DownloadSimple from '@phosphor/download-simple.svg';import { Button } from '@ui';+import { Show } from 'solid-js';export function UnknownContent(props: {fileName: string;+ /** Set while a legacy Office file is being upgraded, e.g. "PowerPoint presentation". */+ convertingTo?: string;onShare: () => void;onDownload: () => void;}) {return (<div class="flex h-full flex-col items-center justify-center"><div class="mx-4 flex w-fit flex-col items-center justify-center gap-4 p-4">- <div class="text-center text-lg">- No preview available for{' '}- <span class="text-ink-muted">{props.fileName}</span>- </div>+ <Show+ when={props.convertingTo}+ fallback={+ <div class="text-center text-lg">+ No preview available for{' '}+ <span class="text-ink-muted">{props.fileName}</span>+ </div>+ }+ >+ {(convertingTo) => (+ <div+ class="flex flex-col items-center gap-2 text-center text-lg"+ data-testid="legacy-office-converting"+ >+ <LoadingSpinner class="size-5" />+ <div>+ Converting <span class="text-ink-muted">{props.fileName}</span>{' '}+ to a {convertingTo()}…+ </div>+ </div>+ )}+ </Show><div class="flex flex-row items-center gap-2"><Button variant="accent" onClick={props.onShare}>diff --git a/apps/web/src/features/block-unknown/legacy-office.test.ts b/apps/web/src/features/block-unknown/legacy-office.test.tsnew file mode 100644index 0000000000..c1e1ae7cb2--- /dev/null+++ b/apps/web/src/features/block-unknown/legacy-office.test.ts@@ -0,0 +1,178 @@+import { describe, expect, it, vi } from 'vitest';+import {+ LEGACY_UPGRADE_WINDOW_MS,+ legacyOfficeUpgradeTarget,+ pollForLegacyUpgrade,+ shouldAwaitLegacyUpgrade,+ upgradedOfficeLabel,+} from './legacy-office';++describe('legacyOfficeUpgradeTarget', () => {+ it('maps legacy Office types to OpenXML', () => {+ expect(legacyOfficeUpgradeTarget('doc')).toBe('docx');+ expect(legacyOfficeUpgradeTarget('ppt')).toBe('pptx');+ expect(legacyOfficeUpgradeTarget('xls')).toBe('xlsx');+ expect(legacyOfficeUpgradeTarget('PPT')).toBe('pptx');+ });++ it('ignores types that are not upgraded', () => {+ for (const fileType of ['docx', 'pptx', 'xlsx', 'xlsm', 'pdf', '', null]) {+ expect(legacyOfficeUpgradeTarget(fileType)).toBeUndefined();+ }+ });++ it('labels each target', () => {+ expect(upgradedOfficeLabel('docx')).toBe('Word document');+ expect(upgradedOfficeLabel('pptx')).toBe('PowerPoint presentation');+ expect(upgradedOfficeLabel('xlsx')).toBe('Excel workbook');+ });+});++describe('shouldAwaitLegacyUpgrade', () => {+ const now = Date.parse('2026-10-06T12:00:00Z');++ it('waits for a recent legacy upload', () => {+ expect(+ shouldAwaitLegacyUpgrade(+ { fileType: 'ppt', createdAt: '2026-10-06T11:59:00Z' },+ now+ )+ ).toBe(true);+ });++ it('does not wait for old legacy documents', () => {+ expect(+ shouldAwaitLegacyUpgrade(+ {+ fileType: 'ppt',+ createdAt: new Date(now - LEGACY_UPGRADE_WINDOW_MS).toISOString(),+ },+ now+ )+ ).toBe(false);+ });++ it('does not wait without a usable creation time or legacy type', () => {+ expect(shouldAwaitLegacyUpgrade({ fileType: 'doc' }, now)).toBe(false);+ expect(+ shouldAwaitLegacyUpgrade(+ { fileType: 'doc', createdAt: 'not a date' },+ now+ )+ ).toBe(false);+ expect(+ shouldAwaitLegacyUpgrade(+ { fileType: 'pdf', createdAt: '2026-10-06T11:59:00Z' },+ now+ )+ ).toBe(false);+ });+});++describe('pollForLegacyUpgrade', () => {+ function clock() {+ let time = 0;+ return {+ now: () => time,+ sleep: vi.fn(async (ms: number) => {+ time += ms;+ }),+ };+ }++ it('resolves once the file type changes', async () => {+ const { now, sleep } = clock();+ const fetchMetadata = vi+ .fn<() => Promise<{ fileType: string }>>()+ .mockResolvedValueOnce({ fileType: 'ppt' })+ .mockResolvedValueOnce({ fileType: 'ppt' })+ .mockResolvedValueOnce({ fileType: 'pptx' });++ const result = await pollForLegacyUpgrade({+ target: 'pptx',+ fetchMetadata,+ fileTypeOf: (m) => m.fileType,+ sleep,+ now,+ intervalMs: 1_000,+ });++ expect(result).toEqual({ fileType: 'pptx' });+ expect(fetchMetadata).toHaveBeenCalledTimes(3);+ expect(sleep).toHaveBeenCalledTimes(2);+ });++ it('retries failed requests', async () => {+ const { now, sleep } = clock();+ const fetchMetadata = vi+ .fn<() => Promise<{ fileType: string }>>()+ .mockRejectedValueOnce(new Error('offline'))+ .mockResolvedValueOnce({ fileType: 'docx' });++ const result = await pollForLegacyUpgrade({+ target: 'docx',+ fetchMetadata,+ fileTypeOf: (m) => m.fileType,+ sleep,+ now,+ });++ expect(result).toEqual({ fileType: 'docx' });+ });++ it('gives up at the timeout', async () => {+ const { now, sleep } = clock();+ const fetchMetadata = vi.fn(async () => ({ fileType: 'xls' }));++ const result = await pollForLegacyUpgrade({+ target: 'xlsx',+ fetchMetadata,+ fileTypeOf: (m) => m.fileType,+ sleep,+ now,+ intervalMs: 1_000,+ timeoutMs: 5_000,+ });++ expect(result).toBeUndefined();+ expect(fetchMetadata).toHaveBeenCalledTimes(5);+ });++ it('stops when aborted', async () => {+ const { now, sleep } = clock();+ const controller = new AbortController();+ const fetchMetadata = vi.fn(async () => {+ controller.abort();+ return { fileType: 'doc' };+ });++ const result = await pollForLegacyUpgrade({+ target: 'docx',+ fetchMetadata,+ fileTypeOf: (m) => m.fileType,+ sleep,+ now,+ signal: controller.signal,+ });++ expect(result).toBeUndefined();+ expect(fetchMetadata).toHaveBeenCalledTimes(1);+ expect(sleep).not.toHaveBeenCalled();+ });++ it('does not accept a different target', async () => {+ const { now, sleep } = clock();++ const result = await pollForLegacyUpgrade({+ target: 'pptx',+ fetchMetadata: async () => ({ fileType: 'docx' }),+ fileTypeOf: (m) => m.fileType,+ sleep,+ now,+ intervalMs: 1_000,+ timeoutMs: 2_000,+ });++ expect(result).toBeUndefined();+ });+});diff --git a/apps/web/src/features/block-unknown/legacy-office.ts b/apps/web/src/features/block-unknown/legacy-office.tsnew file mode 100644index 0000000000..868f5774fd--- /dev/null+++ b/apps/web/src/features/block-unknown/legacy-office.ts@@ -0,0 +1,89 @@+/**+ * Legacy binary Office uploads (.doc, .ppt, .xls) are upgraded to OpenXML on+ * the server shortly after upload. While that runs the document still has its+ * legacy file type and opens here; these helpers decide whether to wait for+ * the upgrade and detect when it lands.+ */++export type UpgradedOfficeType = 'docx' | 'pptx' | 'xlsx';++const UPGRADE_TARGETS: Record<string, UpgradedOfficeType> = {+ doc: 'docx',+ ppt: 'pptx',+ xls: 'xlsx',+};++const UPGRADE_LABELS: Record<UpgradedOfficeType, string> = {+ docx: 'Word document',+ pptx: 'PowerPoint presentation',+ xlsx: 'Excel workbook',+};++/** Documents older than this were uploaded before upgrades or failed them. */+export const LEGACY_UPGRADE_WINDOW_MS = 10 * 60 * 1000;++export function legacyOfficeUpgradeTarget(+ fileType: string | null | undefined+): UpgradedOfficeType | undefined {+ return fileType ? UPGRADE_TARGETS[fileType.toLowerCase()] : undefined;+}++export function upgradedOfficeLabel(target: UpgradedOfficeType): string {+ return UPGRADE_LABELS[target];+}++/** Whether an upgrade for this document may still be on its way. */+export function shouldAwaitLegacyUpgrade(+ document: { fileType?: string | null; createdAt?: string | null },+ now: number+): boolean {+ if (!legacyOfficeUpgradeTarget(document.fileType)) return false;+ if (!document.createdAt) return false;+ const created = Date.parse(document.createdAt);+ if (Number.isNaN(created)) return false;+ return now - created < LEGACY_UPGRADE_WINDOW_MS;+}++export type PollForUpgradeOptions<M> = {+ target: UpgradedOfficeType;+ fetchMetadata: () => Promise<M>;+ fileTypeOf: (metadata: M) => string | null | undefined;+ sleep: (ms: number) => Promise<void>;+ intervalMs?: number;+ timeoutMs?: number;+ now?: () => number;+ signal?: AbortSignal;+};++/**+ * Polls document metadata until its file type becomes `target`. Resolves with+ * that metadata, or `undefined` on timeout or abort. Failed requests are+ * retried until the timeout.+ */+export async function pollForLegacyUpgrade<M>(+ options: PollForUpgradeOptions<M>+): Promise<M | undefined> {+ const {+ target,+ fetchMetadata,+ fileTypeOf,+ sleep,+ intervalMs = 3_000,+ timeoutMs = 3 * 60 * 1000,+ now = Date.now,+ signal,+ } = options;+ const deadline = now() + timeoutMs;++ while (!signal?.aborted && now() < deadline) {+ try {+ const metadata = await fetchMetadata();+ if (fileTypeOf(metadata)?.toLowerCase() === target) return metadata;+ } catch {+ // Keep waiting: a transient failure should not end the wait.+ }+ if (signal?.aborted) break;+ await sleep(intervalMs);+ }+ return undefined;+}diff --git a/apps/web/src/features/channel/Input/accepted-file-types.ts b/apps/web/src/features/channel/Input/accepted-file-types.tsindex 1a391d52c5..3a914e6310 100644--- a/apps/web/src/features/channel/Input/accepted-file-types.ts+++ b/apps/web/src/features/channel/Input/accepted-file-types.ts@@ -38,6 +38,7 @@ export const CHANNEL_DOCUMENT_FILE_EXTENSIONS = ['rtf','txt','xls',+ 'xlsm','xlsx','xml','yaml',diff --git a/apps/web/src/lib/core/client/folderUploadPaths.test.ts b/apps/web/src/lib/core/client/folderUploadPaths.test.tsnew file mode 100644index 0000000000..14be2132b4--- /dev/null+++ b/apps/web/src/lib/core/client/folderUploadPaths.test.ts@@ -0,0 +1,60 @@+import { describe, expect, it } from 'vitest';+import { groupPickedFolderFiles, joinZipPath } from './folderUploadPaths';++const picked = (webkitRelativePath: string) => ({+ name: webkitRelativePath.split('/').at(-1) ?? webkitRelativePath,+ webkitRelativePath,+});++describe('groupPickedFolderFiles', () => {+ it('keeps the picked folder as the first path segment', () => {+ const groups = groupPickedFolderFiles([+ picked('Board Pack/Summary.docx'),+ picked('Board Pack/Finance/Forecasts/Q4.xlsx'),+ picked('Board Pack/Decks/Archive/Old.pptx'),+ ]);++ expect([...groups.keys()]).toEqual(['Board Pack']);+ expect(groups.get('Board Pack')?.details.map((d) => d.path)).toEqual([+ 'Board Pack/Summary.docx',+ 'Board Pack/Finance/Forecasts/Q4.xlsx',+ 'Board Pack/Decks/Archive/Old.pptx',+ ]);+ });++ it('keeps the picked folder when it only holds one subfolder', () => {+ const groups = groupPickedFolderFiles([+ picked('Wrapper/Inner/a.docx'),+ picked('Wrapper/Inner/Deeper/b.pptx'),+ ]);++ expect(groups.get('Wrapper')?.details.map((d) => d.path)).toEqual([+ 'Wrapper/Inner/a.docx',+ 'Wrapper/Inner/Deeper/b.pptx',+ ]);+ });++ it('keeps file objects aligned with their paths', () => {+ const files = [picked('A/x.docx'), picked('B/y.xlsx'), picked('A/z.pptx')];+ const groups = groupPickedFolderFiles(files);++ expect(groups.get('A')?.files).toEqual([files[0], files[2]]);+ expect(groups.get('B')?.files).toEqual([files[1]]);+ });++ it('falls back to the file name without a relative path', () => {+ const groups = groupPickedFolderFiles([+ { name: 'loose.docx', webkitRelativePath: '' },+ ]);++ expect(groups.get('loose.docx')?.details).toEqual([{ path: 'loose.docx' }]);+ });+});++describe('joinZipPath', () => {+ it('joins nested paths', () => {+ expect(joinZipPath('', 'Root')).toBe('Root');+ expect(joinZipPath('Root', 'Sub')).toBe('Root/Sub');+ expect(joinZipPath('Root/Sub', 'a.docx')).toBe('Root/Sub/a.docx');+ });+});diff --git a/apps/web/src/lib/core/client/folderUploadPaths.ts b/apps/web/src/lib/core/client/folderUploadPaths.tsnew file mode 100644index 0000000000..ff2823a089--- /dev/null+++ b/apps/web/src/lib/core/client/folderUploadPaths.ts@@ -0,0 +1,36 @@+import type { FileDetail } from './zipWorkerClient';++type PickedFile = Pick<File, 'name' | 'webkitRelativePath'>;++export interface PickedFolderGroup<F extends PickedFile> {+ files: F[];+ details: FileDetail[];+}++/**+ * Groups files from a folder picker by the folder the user picked.+ *+ * Zip paths keep that folder as their first segment, matching a dropped+ * folder. The server names the upload after the zip's single top folder, so+ * stripping it would rename the upload whenever the picked folder holds just+ * one subfolder.+ */+export function groupPickedFolderFiles<F extends PickedFile>(+ files: F[]+): Map<string, PickedFolderGroup<F>> {+ const groups = new Map<string, PickedFolderGroup<F>>();+ for (const file of files) {+ const relativePath = file.webkitRelativePath || file.name;+ const top = relativePath.split('/')[0] || file.name;+ const group = groups.get(top) ?? { files: [], details: [] };+ group.files.push(file);+ group.details.push({ path: relativePath });+ groups.set(top, group);+ }+ return groups;+}++/** Joins a parent zip path and an entry name. */+export function joinZipPath(parent: string, name: string): string {+ return parent ? `${parent}/${name}` : name;+}diff --git a/apps/web/src/lib/core/client/zipWorker.test.ts b/apps/web/src/lib/core/client/zipWorker.test.tsnew file mode 100644index 0000000000..3787577fcd--- /dev/null+++ b/apps/web/src/lib/core/client/zipWorker.test.ts@@ -0,0 +1,93 @@+import JSZip from 'jszip';+import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';++type WorkerMessage = { type: string; data: { zipBlob?: Blob } };++const posted: WorkerMessage[] = [];++beforeAll(async () => {+ vi.stubGlobal('self', {+ postMessage: (message: WorkerMessage) => posted.push(message),+ });+ // The worker is plain JS with no types; importing it installs `onmessage`.+ const workerModule = '../../workers/folder-upload/zip-worker.js';+ await import(/* @vite-ignore */ workerModule);+});++afterEach(() => {+ posted.length = 0;+});++async function runZip(+ files: { path: string; contents: string }[],+ folderPaths?: string[]+) {+ const self = globalThis.self as unknown as {+ onmessage: (event: { data: unknown }) => void;+ };+ self.onmessage({+ data: {+ taskId: 't',+ action: 'zipFiles',+ files: files.map((f) => new Blob([f.contents])),+ fileDetails: files.map((f) => ({ path: f.path })),+ folderPaths,+ },+ });+ await vi.waitFor(() => {+ expect(+ posted.some((m) => m.type === 'complete' || m.type === 'error')+ ).toBe(true);+ });+ const done = posted.find((m) => m.type === 'complete');+ if (!done?.data.zipBlob) throw new Error(JSON.stringify(posted.at(-1)));+ return JSZip.loadAsync(done.data.zipBlob);+}++describe('zip worker', () => {+ it('writes nested office files under the dropped folder', async () => {+ const zip = await runZip(+ [+ { path: 'Pack/Summary.docx', contents: 'docx' },+ { path: 'Pack/Finance/Forecasts/Q4.xlsx', contents: 'xlsx' },+ { path: 'Pack/Decks/Old.PPTX', contents: 'pptx' },+ ],+ ['Pack', 'Pack/Finance', 'Pack/Finance/Forecasts', 'Pack/Decks']+ );++ expect(+ await zip.file('Pack/Finance/Forecasts/Q4.xlsx')?.async('string')+ ).toBe('xlsx');+ expect(await zip.file('Pack/Decks/Old.PPTX')?.async('string')).toBe('pptx');+ });++ it('keeps empty folders as directory entries', async () => {+ const zip = await runZip(+ [{ path: 'Pack/a.docx', contents: 'a' }],+ ['Pack', 'Pack/Empty', 'Pack/Nested/Empty Leaf']+ );++ const folders = Object.values(zip.files)+ .filter((entry) => entry.dir)+ .map((entry) => entry.name)+ .sort();+ expect(folders).toEqual([+ 'Pack/',+ 'Pack/Empty/',+ 'Pack/Nested/',+ 'Pack/Nested/Empty Leaf/',+ ]);+ });++ it('zips a folder that has no files', async () => {+ const zip = await runZip([], ['Shell', 'Shell/A']);++ expect(Object.keys(zip.files).sort()).toEqual(['Shell/', 'Shell/A/']);+ });++ it('accepts messages without folder paths', async () => {+ const zip = await runZip([{ path: 'Pack/a.docx', contents: 'a' }]);++ expect(zip.file('Pack/a.docx')).not.toBeNull();+ });+});diff --git a/apps/web/src/lib/core/client/zipWorkerClient.ts b/apps/web/src/lib/core/client/zipWorkerClient.tsindex 94b8949a0a..1f1b12c810 100644--- a/apps/web/src/lib/core/client/zipWorkerClient.ts+++ b/apps/web/src/lib/core/client/zipWorkerClient.ts@@ -1,6 +1,7 @@import { analytics } from '@app/lib/analytics';import shortUUID from 'short-uuid';import ZipWorker from '../../workers/folder-upload/zip-worker?worker';+import { joinZipPath } from './folderUploadPaths';const MAX_FOLDER_FILE_COUNT = 1000;// NOTE: you can expect a 30-40% decrease in folder size when zipped@@ -97,6 +98,8 @@ interface ZipTaskMessage {action: 'zipFiles';files: File[];fileDetails: FileDetail[];+ /** Folder paths to write as entries, so empty folders survive. */+ folderPaths: string[];taskId?: string; // Added by the pool}@@ -303,15 +306,14 @@ class ZipWorkerPool {}// zips up each folder entry and returns the zip files-// empty directories are returned as nullexport function handleFoldersInput(entries: FileSystemDirectoryEntry[]-): Promise<File | null>[] {+): Promise<File>[] {if (entries.length === 0) {return [];}- const zipPromises: Promise<File | null>[] = [];+ const zipPromises: Promise<File>[] = [];for (const entry of entries) {const promise = zipDirectory(entry);zipPromises.push(promise);@@ -326,8 +328,15 @@ async function zipDirectory(entry: FileSystemDirectoryEntry) {const fileEntries: FileSystemFileEntry[] = [];const fileDetails: FileDetail[] = [];+ const folderPaths: string[] = [];try {- await processDirectoryEntry(entry, '', fileEntries, fileDetails);+ await processDirectoryEntry(+ entry,+ '',+ fileEntries,+ fileDetails,+ folderPaths+ );} catch (error) {if (error instanceof DirectoryFileCountExceededError) {throw error.setFolderName(folderName);@@ -335,9 +344,8 @@ async function zipDirectory(entry: FileSystemDirectoryEntry) {throw error;}- if (fileEntries.length === 0) {- return null;- } else if (fileEntries.length > MAX_FOLDER_FILE_COUNT) {+ // A folder with no files still uploads, so its (empty) folders are created.+ if (fileEntries.length > MAX_FOLDER_FILE_COUNT) {throw new DirectoryFileCountExceededError(folderName, fileEntries.length);}@@ -360,7 +368,7 @@ async function zipDirectory(entry: FileSystemDirectoryEntry) {const files = await Promise.all(filePromises);- const zipFile = await zipFiles(folderName, files, fileDetails);+ const zipFile = await zipFiles(folderName, files, fileDetails, folderPaths);return zipFile;}@@ -370,14 +378,15 @@ async function processDirectoryEntry(entry: FileSystemEntry,path: string,fileEntries: FileSystemFileEntry[],- fileDetails: FileDetail[]+ fileDetails: FileDetail[],+ folderPaths: string[]): Promise<void> {if (entry.isFile) {if (fileEntries.length > MAX_FOLDER_FILE_COUNT)throw new DirectoryFileCountExceededError();fileEntries.push(entry as FileSystemFileEntry);fileDetails.push({- path: path ? `${path}/${entry.name}` : entry.name,+ path: joinZipPath(path, entry.name),});} else if (entry.isDirectory) {const dirReader = (entry as FileSystemDirectoryEntry).createReader();@@ -402,14 +411,16 @@ async function processDirectoryEntry(}} while (batch.length > 0);- const dirPath = path ? `${path}/${entry.name}` : entry.name;+ const dirPath = joinZipPath(path, entry.name);+ folderPaths.push(dirPath);for (const childEntry of entries) {await processDirectoryEntry(childEntry,dirPath,fileEntries,- fileDetails+ fileDetails,+ folderPaths);}}@@ -418,7 +429,8 @@ async function processDirectoryEntry(export async function zipFiles(folderName: string,files: File[],- fileDetails: FileDetail[]+ fileDetails: FileDetail[],+ folderPaths: string[] = []): Promise<File> {const workerPool = ZipWorkerPool.getInstance(ZipWorker);@@ -426,6 +438,7 @@ export async function zipFiles(action: 'zipFiles',files: files,fileDetails: fileDetails,+ folderPaths,};// check file countdiff --git a/apps/web/src/lib/core/util/upload.ts b/apps/web/src/lib/core/util/upload.tsindex 33b979ccae..8a4e86ee29 100644--- a/apps/web/src/lib/core/util/upload.ts+++ b/apps/web/src/lib/core/util/upload.ts@@ -8,10 +8,10 @@*/import { analytics } from '@app/lib/analytics';+import { groupPickedFolderFiles } from '@core/client/folderUploadPaths';import {DirectoryFileCountExceededError,DirectoryFileSizeExceededError,- type FileDetail,handleFoldersInput,zipFiles,} from '@core/client/zipWorkerClient';@@ -651,20 +651,7 @@ export async function handleFolderSelect(files: File[],onFilesReady: (files: UploadFileEntry[]) => void | Promise<void>): Promise<void> {- const groups = new Map<string, { files: File[]; details: FileDetail[] }>();- for (const file of files) {- const rel = file.webkitRelativePath || file.name;- const parts = rel.split('/');- const top = parts.shift() || file.name;- const path = parts.join('/');- const group = groups.get(top) || {- files: [],- details: [],- };- group.files.push(file);- group.details.push({ path: path || file.name });- groups.set(top, group);- }+ const groups = groupPickedFolderFiles(files);const zipEntryPromises = Array.from(groups.entries()).map(([folderName, group]) =>diff --git a/apps/web/src/lib/service-clients/service-cognition/generated/schemas/fileType.ts b/apps/web/src/lib/service-clients/service-cognition/generated/schemas/fileType.tsindex 99f674b825..6066bbd257 100644--- a/apps/web/src/lib/service-clients/service-cognition/generated/schemas/fileType.ts+++ b/apps/web/src/lib/service-clients/service-cognition/generated/schemas/fileType.ts@@ -410,7 +410,9 @@ export const FileType = {azw3: 'azw3',djvu: 'djvu',xls: 'xls',+ xlsm: 'xlsm',ppt: 'ppt',+ doc: 'doc',pptx: 'pptx',xlsx: 'xlsx',db: 'db',diff --git a/apps/web/src/lib/service-clients/service-cognition/openapi.json b/apps/web/src/lib/service-clients/service-cognition/openapi.jsonindex 60c809ff1f..a409791479 100644--- a/apps/web/src/lib/service-clients/service-cognition/openapi.json+++ b/apps/web/src/lib/service-clients/service-cognition/openapi.json@@ -3600,7 +3600,9 @@"azw3","djvu","xls",+ "xlsm","ppt",+ "doc","pptx","xlsx","db",diff --git a/apps/web/src/lib/service-clients/service-connection/bulkUpload.ts b/apps/web/src/lib/service-clients/service-connection/bulkUpload.tsindex ffb0550313..2f419346cd 100644--- a/apps/web/src/lib/service-clients/service-connection/bulkUpload.ts+++ b/apps/web/src/lib/service-clients/service-connection/bulkUpload.ts@@ -67,6 +67,7 @@ createWebsocketEventEffect<switch (update.status) {case 'partially_completed':projectId = update.projectId;+ toast.alert('Some files in the folder could not be uploaded');break;case 'completed':projectId = update.projectId;diff --git a/apps/web/src/lib/service-clients/service-search/generated/models/fileType.ts b/apps/web/src/lib/service-clients/service-search/generated/models/fileType.tsindex 04174c498b..00c4aef481 100644--- a/apps/web/src/lib/service-clients/service-search/generated/models/fileType.ts+++ b/apps/web/src/lib/service-clients/service-search/generated/models/fileType.ts@@ -410,7 +410,9 @@ export const FileType = {azw3: 'azw3',djvu: 'djvu',xls: 'xls',+ xlsm: 'xlsm',ppt: 'ppt',+ doc: 'doc',pptx: 'pptx',xlsx: 'xlsx',db: 'db',diff --git a/apps/web/src/lib/service-clients/service-search/openapi.json b/apps/web/src/lib/service-clients/service-search/openapi.jsonindex 587ec52d4b..742ad60759 100644--- a/apps/web/src/lib/service-clients/service-search/openapi.json+++ b/apps/web/src/lib/service-clients/service-search/openapi.json@@ -2636,7 +2636,9 @@"azw3","djvu","xls",+ "xlsm","ppt",+ "doc","pptx","xlsx","db",diff --git a/apps/web/src/lib/service-clients/service-storage/fileTypeMap.ts b/apps/web/src/lib/service-clients/service-storage/fileTypeMap.tsindex b42d9c4020..449dcd10a6 100644--- a/apps/web/src/lib/service-clients/service-storage/fileTypeMap.ts+++ b/apps/web/src/lib/service-clients/service-storage/fileTypeMap.ts@@ -508,11 +508,17 @@ export const FileTypeMap = {},djvu: { extension: 'djvu', mime: 'image/vnd.djvu', app: 'document' },xls: { extension: 'xls', mime: 'application/vnd.ms-excel', app: 'document' },+ xlsm: {+ extension: 'xlsm',+ mime: 'application/vnd.ms-excel.sheet.macroEnabled.12',+ app: 'document',+ },ppt: {extension: 'ppt',mime: 'application/vnd.ms-powerpoint',app: 'document',},+ doc: { extension: 'doc', mime: 'application/msword', app: 'document' },pptx: { extension: 'pptx', mime: 'application/xml', app: 'document' },xlsx: { extension: 'xlsx', mime: 'application/xml', app: 'document' },db: { extension: 'db', mime: 'application/octet-stream', app: 'database' },diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/fileType.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/fileType.tsindex 44b84118a9..054d59496d 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/fileType.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/fileType.ts@@ -410,7 +410,9 @@ export const FileType = {azw3: 'azw3',djvu: 'djvu',xls: 'xls',+ xlsm: 'xlsm',ppt: 'ppt',+ doc: 'doc',pptx: 'pptx',xlsx: 'xlsx',db: 'db',diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/uploadFolderRequest.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/uploadFolderRequest.tsindex dd0eaeb9b8..329b4b5181 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/uploadFolderRequest.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/uploadFolderRequest.ts@@ -10,6 +10,10 @@ import type { UploadFolderRequestParentId } from './uploadFolderRequestParentId'export interface UploadFolderRequest {/** The content of the folder */content: FolderItem[];+ /** Relative paths of folders to create even when they hold no files.++Uses the same shape as [FolderItem::relative_path], root folder included. */+ folders?: string[];/** Optional parent project id to upload the folder into */parentId?: UploadFolderRequestParentId;/** The name of the folder you are uploading.diff --git a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts b/apps/web/src/lib/service-clients/service-storage/generated/zod.tsindex c627f88610..0f45da019c 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/zod.ts@@ -11719,7 +11719,9 @@ export const editDocumentBody = zod'azw3','djvu','xls',+ 'xlsm','ppt',+ 'doc','pptx','xlsx','db',@@ -39742,7 +39744,9 @@ export const uploadFolderHandlerBody = zod.object({'azw3','djvu','xls',+ 'xlsm','ppt',+ 'doc','pptx','xlsx','db',@@ -39804,6 +39808,12 @@ export const uploadFolderHandlerBody = zod.object({})).describe('The content of the folder'),+ folders: zod+ .array(zod.string())+ .optional()+ .describe(+ 'Relative paths of folders to create even when they hold no files.\n\nUses the same shape as [FolderItem::relative_path], root folder included.'+ ),parentId: zod.string().nullish()@@ -40240,7 +40250,9 @@ export const uploadFolderHandlerResponse = zod.object({'azw3','djvu','xls',+ 'xlsm','ppt',+ 'doc','pptx','xlsx','db',diff --git a/apps/web/src/lib/service-clients/service-storage/openapi.json b/apps/web/src/lib/service-clients/service-storage/openapi.jsonindex 5b23562460..7e0ef8fbce 100644--- a/apps/web/src/lib/service-clients/service-storage/openapi.json+++ b/apps/web/src/lib/service-clients/service-storage/openapi.json@@ -25169,7 +25169,9 @@"azw3","djvu","xls",+ "xlsm","ppt",+ "doc","pptx","xlsx","db",@@ -35822,6 +35824,13 @@},"description": "The content of the folder"},+ "folders": {+ "type": "array",+ "items": {+ "type": "string"+ },+ "description": "Relative paths of folders to create even when they hold no files.\n\nUses the same shape as [FolderItem::relative_path], root folder included."+ },"parentId": {"type": ["string", "null"],"description": "Optional parent project id to upload the folder into"diff --git a/apps/web/src/lib/workers/folder-upload/zip-worker.js b/apps/web/src/lib/workers/folder-upload/zip-worker.jsindex 4f961589d3..62622496e4 100644--- a/apps/web/src/lib/workers/folder-upload/zip-worker.js+++ b/apps/web/src/lib/workers/folder-upload/zip-worker.js@@ -1,7 +1,7 @@import JSZip from 'jszip';self.onmessage = function (event) {- const { taskId, action, files, fileDetails } = event.data;+ const { taskId, action, files, fileDetails, folderPaths } = event.data;if (action === 'zipFiles') {self.postMessage({@@ -12,13 +12,18 @@ self.onmessage = function (event) {},});- zipFiles(taskId, files, fileDetails);+ zipFiles(taskId, files, fileDetails, folderPaths ?? []);}};-async function zipFiles(taskId, files, fileDetails) {+async function zipFiles(taskId, files, fileDetails, folderPaths) {try {const zip = new JSZip();++ // Explicit folder entries keep empty folders in the upload.+ for (const folderPath of folderPaths) {+ zip.folder(folderPath);+ }const totalFiles = files.length;let processedFiles = 0;diff --git a/crates/document_storage_service_client/src/upload.rs b/crates/document_storage_service_client/src/upload.rsindex bec2d74b6c..71618ba42a 100644--- a/crates/document_storage_service_client/src/upload.rs+++ b/crates/document_storage_service_client/src/upload.rs@@ -15,6 +15,7 @@ impl DocumentStorageServiceClient {user_id: String,root_folder_name: String,content: Vec<FolderItem>,+ folders: Vec<String>,upload_request_id: String,parent_id: Option<String>,) -> anyhow::Result<UploadFolderResponseData> {@@ -25,6 +26,7 @@ impl DocumentStorageServiceClient {root_folder_name,upload_request_id,parent_id,+ folders,};let response = selfdiff --git a/crates/documents/src/domain.rs b/crates/documents/src/domain.rsindex 7a699c4f6b..e1518e3099 100644--- a/crates/documents/src/domain.rs+++ b/crates/documents/src/domain.rs@@ -25,6 +25,10 @@ pub mod starter;#[cfg(feature = "ports")]pub mod upload_finalize;+/// Legacy Office (.doc/.ppt/.xls) upgrades to OpenXML.+#[cfg(feature = "ports")]+pub mod legacy_office_upgrade;+pub mod models;#[cfg(feature = "axum")]pub mod permission_token;diff --git a/crates/documents/src/domain/legacy_office_upgrade.rs b/crates/documents/src/domain/legacy_office_upgrade.rsnew file mode 100644index 0000000000..e779327cd5--- /dev/null+++ b/crates/documents/src/domain/legacy_office_upgrade.rs@@ -0,0 +1,336 @@+//! Upgrading legacy binary Office uploads (`.doc`, `.ppt`, `.xls`) to their+//! OpenXML equivalents so they open in the native Word, PowerPoint, and+//! spreadsheet surfaces.+//!+//! The upgrade runs in two steps, both driven by object-created events:+//!+//! 1. When the legacy original lands, [`LegacyOfficeUpgrader::request_upgrade`]+//! asks the conversion service to write `upgraded.{docx,pptx,xlsx}` next to+//! it. The original stays ready, so the document is downloadable even if+//! conversion fails.+//! 2. When the upgraded object lands, [`LegacyOfficeUpgrader::apply_upgrade`]+//! makes it the document's current version and switches the file type.+//! PowerPoint and Excel become a new document instance; Word becomes a new+//! DOCX BOM staged for the regular DOCX pipeline.++use std::future::Future;++use model::document::{DocumentBasic, FileType};+use model_owner::Owner;++use super::content::{DocumentContent, DocumentContentLocation};+use super::models::DocumentError;++/// The OpenXML format a legacy binary Office type is upgraded to.+pub fn upgrade_target(file_type: FileType) -> Option<FileType> {+ match file_type {+ FileType::Doc => Some(FileType::Docx),+ FileType::Ppt => Some(FileType::Pptx),+ FileType::Xls => Some(FileType::Xlsx),+ _ => None,+ }+}++/// The legacy binary Office type an OpenXML format is upgraded from.+pub fn upgrade_source(target: FileType) -> Option<FileType> {+ match target {+ FileType::Docx => Some(FileType::Doc),+ FileType::Pptx => Some(FileType::Ppt),+ FileType::Xlsx => Some(FileType::Xls),+ _ => None,+ }+}++/// A request to convert a legacy original into its OpenXML equivalent.+#[derive(Clone, Debug, Eq, PartialEq)]+pub struct LegacyOfficeUpgradeRequest {+ /// The document owner, which prefixes every object key.+ pub owner: Owner,+ /// The document being upgraded.+ pub document_id: String,+ /// The version holding the legacy original.+ pub source_version_id: i64,+ /// The legacy type.+ pub from: FileType,+ /// The OpenXML type.+ pub to: FileType,+}++/// Where the upgraded object is copied to become the document's content.+#[derive(Clone, Copy, Debug, Eq, PartialEq)]+pub enum UpgradedObjectDestination {+ /// A document instance in the document storage bucket.+ DocumentVersion {+ /// The new document instance id.+ version_id: i64,+ },+ /// A DOCX BOM in the DOCX staging bucket, picked up by the DOCX pipeline.+ DocxStaging {+ /// The new DOCX BOM id.+ bom_id: i64,+ },+}++/// Object storage and conversion capabilities for legacy upgrades.+pub trait LegacyOfficeUpgradeStoragePort: Send + Sync {+ /// Ask the conversion service to write the upgraded object.+ fn request_upgrade(+ &self,+ request: &LegacyOfficeUpgradeRequest,+ ) -> impl Future<Output = Result<(), DocumentError>> + Send;++ /// SHA-256 of the upgraded object, recorded on the new document instance.+ fn upgraded_object_sha(+ &self,+ owner: &Owner,+ document_id: &str,+ target: FileType,+ ) -> impl Future<Output = Result<String, DocumentError>> + Send;++ /// Copy the upgraded object to the destination that serves it.+ fn promote_upgraded_object(+ &self,+ owner: &Owner,+ document_id: &str,+ target: FileType,+ destination: UpgradedObjectDestination,+ ) -> impl Future<Output = Result<(), DocumentError>> + Send;+}++/// Document persistence needed to swap in an upgraded version.+pub trait LegacyOfficeUpgradeRepoPort: Send + Sync {+ /// Insert a document instance (version) and return its id.+ fn create_document_instance(+ &self,+ document_id: &str,+ sha: &str,+ ) -> impl Future<Output = Result<i64, DocumentError>> + Send;++ /// Delete a document instance created for an upgrade that did not finish.+ fn delete_document_instance(+ &self,+ version_id: i64,+ ) -> impl Future<Output = Result<(), DocumentError>> + Send;++ /// Insert a DOCX BOM (version) and return its id.+ fn create_document_bom(+ &self,+ document_id: &str,+ ) -> impl Future<Output = Result<i64, DocumentError>> + Send;++ /// Delete a DOCX BOM created for an upgrade that did not finish.+ fn delete_document_bom(+ &self,+ bom_id: i64,+ ) -> impl Future<Output = Result<(), DocumentError>> + Send;++ /// Change the document's file type from `from` to `to` if it is still+ /// `from`. Returns whether this call made the change.+ fn swap_document_file_type(+ &self,+ document_id: &str,+ from: FileType,+ to: FileType,+ ) -> impl Future<Output = Result<bool, DocumentError>> + Send;++ /// Persist content lifecycle metadata.+ fn set_document_content(+ &self,+ document_id: &str,+ content: DocumentContent,+ ) -> impl Future<Output = Result<(), DocumentError>> + Send;+}++/// What [`LegacyOfficeUpgrader::apply_upgrade`] did.+#[derive(Clone, Copy, Debug, Eq, PartialEq)]+pub enum UpgradeOutcome {+ /// The upgraded object is now the document's content.+ Applied,+ /// The document is not (or no longer) the legacy source of this upgrade,+ /// e.g. a redelivered event after the upgrade already applied.+ Skipped,+}++/// Runs both steps of a legacy Office upgrade.+pub struct LegacyOfficeUpgrader<'a, R, S> {+ repo: &'a R,+ storage: &'a S,+}++impl<'a, R, S> LegacyOfficeUpgrader<'a, R, S>+where+ R: LegacyOfficeUpgradeRepoPort,+ S: LegacyOfficeUpgradeStoragePort,+{+ /// Construct an upgrader.+ pub fn new(repo: &'a R, storage: &'a S) -> Self {+ Self { repo, storage }+ }++ /// Request an upgrade when `version_id` holds a legacy Office original.+ /// Returns whether one was requested.+ #[tracing::instrument(skip(self, document_context), fields(document_id = %document_context.document_id), err)]+ pub async fn request_upgrade(+ &self,+ document_context: &DocumentBasic,+ version_id: i64,+ ) -> Result<bool, DocumentError> {+ let Some(from) = document_context.try_file_type() else {+ return Ok(false);+ };+ let Some(to) = upgrade_target(from) else {+ return Ok(false);+ };++ self.storage+ .request_upgrade(&LegacyOfficeUpgradeRequest {+ owner: document_context.owner.clone(),+ document_id: document_context.document_id.clone(),+ source_version_id: version_id,+ from,+ to,+ })+ .await?;+ Ok(true)+ }++ /// Make the upgraded `target` object the document's content.+ ///+ /// Safe to repeat: once applied, the file type no longer matches the+ /// legacy source and later calls skip. The file type is swapped before+ /// the object is copied so the copy's own object-created event sees the+ /// new type and does not request another upgrade.+ #[tracing::instrument(skip(self, document_context), fields(document_id = %document_context.document_id), err)]+ pub async fn apply_upgrade(+ &self,+ document_context: &DocumentBasic,+ target: FileType,+ ) -> Result<UpgradeOutcome, DocumentError> {+ let Some(source) = upgrade_source(target) else {+ return Err(DocumentError::BadRequest(format!(+ "{target} is not an upgrade target"+ )));+ };+ if document_context.try_file_type() != Some(source) {+ return Ok(UpgradeOutcome::Skipped);+ }++ match target {+ FileType::Docx => self.apply_docx_upgrade(document_context, source).await,+ _ => {+ self.apply_versioned_upgrade(document_context, source, target)+ .await+ }+ }+ }++ async fn apply_versioned_upgrade(+ &self,+ document_context: &DocumentBasic,+ source: FileType,+ target: FileType,+ ) -> Result<UpgradeOutcome, DocumentError> {+ let document_id = &document_context.document_id;+ let owner = &document_context.owner;++ let sha = self+ .storage+ .upgraded_object_sha(owner, document_id, target)+ .await?;+ let version_id = self+ .repo+ .create_document_instance(document_id, &sha)+ .await?;++ if !self+ .repo+ .swap_document_file_type(document_id, source, target)+ .await?+ {+ self.repo.delete_document_instance(version_id).await?;+ return Ok(UpgradeOutcome::Skipped);+ }++ if let Err(error) = self+ .storage+ .promote_upgraded_object(+ owner,+ document_id,+ target,+ UpgradedObjectDestination::DocumentVersion { version_id },+ )+ .await+ {+ self.repo+ .swap_document_file_type(document_id, target, source)+ .await?;+ self.repo.delete_document_instance(version_id).await?;+ return Err(error);+ }++ self.repo+ .set_document_content(+ document_id,+ DocumentContent::ready(DocumentContentLocation::ObjectStorage),+ )+ .await?;+ Ok(UpgradeOutcome::Applied)+ }++ async fn apply_docx_upgrade(+ &self,+ document_context: &DocumentBasic,+ source: FileType,+ ) -> Result<UpgradeOutcome, DocumentError> {+ let document_id = &document_context.document_id;+ let owner = &document_context.owner;++ let bom_id = self.repo.create_document_bom(document_id).await?;++ if !self+ .repo+ .swap_document_file_type(document_id, source, FileType::Docx)+ .await?+ {+ self.repo.delete_document_bom(bom_id).await?;+ return Ok(UpgradeOutcome::Skipped);+ }++ // The DOCX pipeline marks the content ready once it has processed the+ // staged file, exactly as for a DOCX upload.+ self.repo+ .set_document_content(+ document_id,+ DocumentContent::pending_at(DocumentContentLocation::ConvertedPdf),+ )+ .await?;++ if let Err(error) = self+ .storage+ .promote_upgraded_object(+ owner,+ document_id,+ FileType::Docx,+ UpgradedObjectDestination::DocxStaging { bom_id },+ )+ .await+ {+ self.repo+ .swap_document_file_type(document_id, FileType::Docx, source)+ .await?;+ self.repo.delete_document_bom(bom_id).await?;+ self.repo+ .set_document_content(+ document_id,+ DocumentContent::ready(DocumentContentLocation::ObjectStorage),+ )+ .await?;+ return Err(error);+ }++ Ok(UpgradeOutcome::Applied)+ }+}++#[cfg(test)]+mod tests;diff --git a/crates/documents/src/domain/legacy_office_upgrade/tests.rs b/crates/documents/src/domain/legacy_office_upgrade/tests.rsnew file mode 100644index 0000000000..21c15b5519--- /dev/null+++ b/crates/documents/src/domain/legacy_office_upgrade/tests.rs@@ -0,0 +1,556 @@+use std::str::FromStr;+use std::sync::Mutex;++use super::*;+use crate::domain::content::DocumentContentState;++const DOCUMENT_ID: &str = "doc-1";++#[derive(Clone, Debug, PartialEq)]+enum Call {+ RequestUpgrade(LegacyOfficeUpgradeRequest),+ Sha(FileType),+ Promote(FileType, UpgradedObjectDestination),+ CreateInstance(String),+ DeleteInstance(i64),+ CreateBom,+ DeleteBom(i64),+ Swap(FileType, FileType),+ SetContent(DocumentContentState, Option<DocumentContentLocation>),+}++#[derive(Default)]+struct Fake {+ calls: Mutex<Vec<Call>>,+ /// The document's stored file type, which swaps compare against.+ file_type: Mutex<Option<FileType>>,+ fail_promote: bool,+ fail_sha: bool,+ fail_request: bool,+}++impl Fake {+ fn with_type(file_type: FileType) -> Self {+ Self {+ file_type: Mutex::new(Some(file_type)),+ ..Self::default()+ }+ }++ fn record(&self, call: Call) {+ self.calls.lock().unwrap().push(call);+ }++ fn calls(&self) -> Vec<Call> {+ self.calls.lock().unwrap().clone()+ }++ fn stored_type(&self) -> Option<FileType> {+ *self.file_type.lock().unwrap()+ }+}++fn storage_error() -> DocumentError {+ DocumentError::Internal(anyhow::anyhow!("storage unavailable"))+}++impl LegacyOfficeUpgradeStoragePort for Fake {+ async fn request_upgrade(+ &self,+ request: &LegacyOfficeUpgradeRequest,+ ) -> Result<(), DocumentError> {+ self.record(Call::RequestUpgrade(request.clone()));+ if self.fail_request {+ return Err(storage_error());+ }+ Ok(())+ }++ async fn upgraded_object_sha(+ &self,+ _owner: &Owner,+ _document_id: &str,+ target: FileType,+ ) -> Result<String, DocumentError> {+ self.record(Call::Sha(target));+ if self.fail_sha {+ return Err(storage_error());+ }+ Ok("upgraded-sha".to_string())+ }++ async fn promote_upgraded_object(+ &self,+ _owner: &Owner,+ _document_id: &str,+ target: FileType,+ destination: UpgradedObjectDestination,+ ) -> Result<(), DocumentError> {+ self.record(Call::Promote(target, destination));+ if self.fail_promote {+ return Err(storage_error());+ }+ Ok(())+ }+}++impl LegacyOfficeUpgradeRepoPort for Fake {+ async fn create_document_instance(+ &self,+ _document_id: &str,+ sha: &str,+ ) -> Result<i64, DocumentError> {+ self.record(Call::CreateInstance(sha.to_string()));+ Ok(42)+ }++ async fn delete_document_instance(&self, version_id: i64) -> Result<(), DocumentError> {+ self.record(Call::DeleteInstance(version_id));+ Ok(())+ }++ async fn create_document_bom(&self, _document_id: &str) -> Result<i64, DocumentError> {+ self.record(Call::CreateBom);+ Ok(7)+ }++ async fn delete_document_bom(&self, bom_id: i64) -> Result<(), DocumentError> {+ self.record(Call::DeleteBom(bom_id));+ Ok(())+ }++ async fn swap_document_file_type(+ &self,+ _document_id: &str,+ from: FileType,+ to: FileType,+ ) -> Result<bool, DocumentError> {+ self.record(Call::Swap(from, to));+ let mut stored = self.file_type.lock().unwrap();+ if *stored != Some(from) {+ return Ok(false);+ }+ *stored = Some(to);+ Ok(true)+ }++ async fn set_document_content(+ &self,+ _document_id: &str,+ content: DocumentContent,+ ) -> Result<(), DocumentError> {+ self.record(Call::SetContent(content.state, content.location));+ Ok(())+ }+}++fn owner() -> Owner {+ Owner::from_principal_str("macro|[email protected]").unwrap()+}++fn document(file_type: Option<&str>) -> DocumentBasic {+ DocumentBasic {+ document_id: DOCUMENT_ID.to_string(),+ document_name: "Quarterly".to_string(),+ owner: owner(),+ file_type: file_type.map(str::to_string),+ sub_type: None,+ branched_from_id: None,+ branched_from_version_id: None,+ document_family_id: None,+ project_id: None,+ deleted_at: None,+ }+}++#[test]+fn legacy_types_map_to_openxml_and_back() {+ for (legacy, openxml) in [+ (FileType::Doc, FileType::Docx),+ (FileType::Ppt, FileType::Pptx),+ (FileType::Xls, FileType::Xlsx),+ ] {+ assert_eq!(upgrade_target(legacy), Some(openxml));+ assert_eq!(upgrade_source(openxml), Some(legacy));+ }+}++#[test]+fn other_types_have_no_upgrade() {+ for file_type in [+ FileType::Docx,+ FileType::Pptx,+ FileType::Xlsx,+ FileType::Xlsm,+ FileType::Pdf,+ FileType::Md,+ FileType::Spreadsheet,+ ] {+ assert_eq!(upgrade_target(file_type), None, "{file_type}");+ }+ for file_type in [+ FileType::Doc,+ FileType::Ppt,+ FileType::Xls,+ FileType::Pdf,+ FileType::Xlsm,+ ] {+ assert_eq!(upgrade_source(file_type), None, "{file_type}");+ }+}++#[tokio::test]+async fn requests_upgrade_for_each_legacy_type() {+ for (legacy, openxml) in [+ ("doc", FileType::Docx),+ ("ppt", FileType::Pptx),+ ("xls", FileType::Xlsx),+ ] {+ let fake = Fake::default();+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let requested = upgrader+ .request_upgrade(&document(Some(legacy)), 11)+ .await+ .unwrap();++ assert!(requested, "{legacy}");+ assert_eq!(+ fake.calls(),+ vec![Call::RequestUpgrade(LegacyOfficeUpgradeRequest {+ owner: owner(),+ document_id: DOCUMENT_ID.to_string(),+ source_version_id: 11,+ from: FileType::from_str(legacy).unwrap(),+ to: openxml,+ })]+ );+ }+}++#[tokio::test]+async fn requests_upgrade_for_uppercase_stored_type() {+ let fake = Fake::default();+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ assert!(+ upgrader+ .request_upgrade(&document(Some("PPT")), 3)+ .await+ .unwrap()+ );+}++#[tokio::test]+async fn does_not_request_upgrade_for_modern_or_unknown_types() {+ for file_type in [+ Some("docx"),+ Some("pptx"),+ Some("xlsx"),+ Some("xlsm"),+ Some("pdf"),+ Some("not-a-type"),+ None,+ ] {+ let fake = Fake::default();+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let requested = upgrader+ .request_upgrade(&document(file_type), 1)+ .await+ .unwrap();++ assert!(!requested, "{file_type:?}");+ assert!(fake.calls().is_empty(), "{file_type:?}");+ }+}++#[tokio::test]+async fn request_failure_is_returned() {+ let fake = Fake {+ fail_request: true,+ ..Fake::default()+ };+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ assert!(+ upgrader+ .request_upgrade(&document(Some("doc")), 1)+ .await+ .is_err()+ );+}++#[tokio::test]+async fn applies_presentation_upgrade_as_new_version() {+ let fake = Fake::with_type(FileType::Ppt);+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let outcome = upgrader+ .apply_upgrade(&document(Some("ppt")), FileType::Pptx)+ .await+ .unwrap();++ assert_eq!(outcome, UpgradeOutcome::Applied);+ assert_eq!(fake.stored_type(), Some(FileType::Pptx));+ assert_eq!(+ fake.calls(),+ vec![+ Call::Sha(FileType::Pptx),+ Call::CreateInstance("upgraded-sha".to_string()),+ // The type changes before the copy, so the copy's object-created+ // event sees pptx and requests nothing.+ Call::Swap(FileType::Ppt, FileType::Pptx),+ Call::Promote(+ FileType::Pptx,+ UpgradedObjectDestination::DocumentVersion { version_id: 42 }+ ),+ Call::SetContent(+ DocumentContentState::Ready,+ Some(DocumentContentLocation::ObjectStorage)+ ),+ ]+ );+}++#[tokio::test]+async fn applies_workbook_upgrade_as_new_version() {+ let fake = Fake::with_type(FileType::Xls);+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let outcome = upgrader+ .apply_upgrade(&document(Some("xls")), FileType::Xlsx)+ .await+ .unwrap();++ assert_eq!(outcome, UpgradeOutcome::Applied);+ assert_eq!(fake.stored_type(), Some(FileType::Xlsx));+ assert!(fake.calls().contains(&Call::Promote(+ FileType::Xlsx,+ UpgradedObjectDestination::DocumentVersion { version_id: 42 }+ )));+}++#[tokio::test]+async fn applies_word_upgrade_through_the_docx_pipeline() {+ let fake = Fake::with_type(FileType::Doc);+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let outcome = upgrader+ .apply_upgrade(&document(Some("doc")), FileType::Docx)+ .await+ .unwrap();++ assert_eq!(outcome, UpgradeOutcome::Applied);+ assert_eq!(fake.stored_type(), Some(FileType::Docx));+ assert_eq!(+ fake.calls(),+ vec![+ Call::CreateBom,+ Call::Swap(FileType::Doc, FileType::Docx),+ Call::SetContent(+ DocumentContentState::Pending,+ Some(DocumentContentLocation::ConvertedPdf)+ ),+ Call::Promote(+ FileType::Docx,+ UpgradedObjectDestination::DocxStaging { bom_id: 7 }+ ),+ ]+ );+}++#[tokio::test]+async fn skips_when_already_upgraded() {+ for (stored, target) in [+ ("pptx", FileType::Pptx),+ ("docx", FileType::Docx),+ ("xlsx", FileType::Xlsx),+ ] {+ let fake = Fake::default();+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let outcome = upgrader+ .apply_upgrade(&document(Some(stored)), target)+ .await+ .unwrap();++ assert_eq!(outcome, UpgradeOutcome::Skipped, "{stored}");+ assert!(fake.calls().is_empty(), "{stored}");+ }+}++#[tokio::test]+async fn skips_when_the_upgrade_is_for_a_different_legacy_type() {+ let fake = Fake::with_type(FileType::Doc);+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let outcome = upgrader+ .apply_upgrade(&document(Some("doc")), FileType::Pptx)+ .await+ .unwrap();++ assert_eq!(outcome, UpgradeOutcome::Skipped);+ assert!(fake.calls().is_empty());+}++#[tokio::test]+async fn rejects_non_upgrade_targets() {+ let fake = Fake::with_type(FileType::Pdf);+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let error = upgrader+ .apply_upgrade(&document(Some("pdf")), FileType::Pdf)+ .await+ .unwrap_err();++ assert!(matches!(error, DocumentError::BadRequest(_)));+ assert!(fake.calls().is_empty());+}++#[tokio::test]+async fn concurrent_apply_that_loses_the_swap_cleans_up() {+ // Another delivery already swapped the type after this one read it.+ let fake = Fake::with_type(FileType::Pptx);+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let outcome = upgrader+ .apply_upgrade(&document(Some("ppt")), FileType::Pptx)+ .await+ .unwrap();++ assert_eq!(outcome, UpgradeOutcome::Skipped);+ assert_eq!(+ fake.calls(),+ vec![+ Call::Sha(FileType::Pptx),+ Call::CreateInstance("upgraded-sha".to_string()),+ Call::Swap(FileType::Ppt, FileType::Pptx),+ Call::DeleteInstance(42),+ ]+ );+}++#[tokio::test]+async fn concurrent_docx_apply_that_loses_the_swap_cleans_up() {+ let fake = Fake::with_type(FileType::Docx);+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let outcome = upgrader+ .apply_upgrade(&document(Some("doc")), FileType::Docx)+ .await+ .unwrap();++ assert_eq!(outcome, UpgradeOutcome::Skipped);+ assert_eq!(+ fake.calls(),+ vec![+ Call::CreateBom,+ Call::Swap(FileType::Doc, FileType::Docx),+ Call::DeleteBom(7)+ ]+ );+}++#[tokio::test]+async fn failed_copy_restores_the_legacy_document() {+ let fake = Fake {+ fail_promote: true,+ ..Fake::with_type(FileType::Xls)+ };+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let result = upgrader+ .apply_upgrade(&document(Some("xls")), FileType::Xlsx)+ .await;++ assert!(result.is_err());+ assert_eq!(fake.stored_type(), Some(FileType::Xls));+ assert_eq!(+ fake.calls()[3..],+ [+ Call::Promote(+ FileType::Xlsx,+ UpgradedObjectDestination::DocumentVersion { version_id: 42 }+ ),+ Call::Swap(FileType::Xlsx, FileType::Xls),+ Call::DeleteInstance(42),+ ]+ );+}++#[tokio::test]+async fn failed_docx_staging_restores_the_legacy_document() {+ let fake = Fake {+ fail_promote: true,+ ..Fake::with_type(FileType::Doc)+ };+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let result = upgrader+ .apply_upgrade(&document(Some("doc")), FileType::Docx)+ .await;++ assert!(result.is_err());+ assert_eq!(fake.stored_type(), Some(FileType::Doc));+ assert_eq!(+ fake.calls()[3..],+ [+ Call::Promote(+ FileType::Docx,+ UpgradedObjectDestination::DocxStaging { bom_id: 7 }+ ),+ Call::Swap(FileType::Docx, FileType::Doc),+ Call::DeleteBom(7),+ Call::SetContent(+ DocumentContentState::Ready,+ Some(DocumentContentLocation::ObjectStorage)+ ),+ ]+ );+}++#[tokio::test]+async fn unreadable_upgrade_writes_nothing() {+ let fake = Fake {+ fail_sha: true,+ ..Fake::with_type(FileType::Ppt)+ };+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let result = upgrader+ .apply_upgrade(&document(Some("ppt")), FileType::Pptx)+ .await;++ assert!(result.is_err());+ assert_eq!(fake.calls(), vec![Call::Sha(FileType::Pptx)]);+ assert_eq!(fake.stored_type(), Some(FileType::Ppt));+}++#[tokio::test]+async fn applying_twice_applies_once() {+ let fake = Fake::with_type(FileType::Ppt);+ let upgrader = LegacyOfficeUpgrader::new(&fake, &fake);++ let first = upgrader+ .apply_upgrade(&document(Some("ppt")), FileType::Pptx)+ .await+ .unwrap();+ // A redelivered event reloads the document, which is now a pptx.+ let second = upgrader+ .apply_upgrade(&document(Some("pptx")), FileType::Pptx)+ .await+ .unwrap();++ assert_eq!(+ (first, second),+ (UpgradeOutcome::Applied, UpgradeOutcome::Skipped)+ );+ assert_eq!(+ fake.calls()+ .iter()+ .filter(|call| matches!(call, Call::CreateInstance(_)))+ .count(),+ 1+ );+}diff --git a/crates/documents/src/outbound/pg_document_repo.rs b/crates/documents/src/outbound/pg_document_repo.rsindex e9e1ef2312..d1adefcbb0 100644--- a/crates/documents/src/outbound/pg_document_repo.rs+++ b/crates/documents/src/outbound/pg_document_repo.rs@@ -8,6 +8,7 @@ mod tests;mod copy;mod create;mod edit;+mod legacy_upgrade;mod markdown_backfill;mod share;diff --git a/crates/documents/src/outbound/pg_document_repo/legacy_upgrade.rs b/crates/documents/src/outbound/pg_document_repo/legacy_upgrade.rsnew file mode 100644index 0000000000..9e715f37f8--- /dev/null+++ b/crates/documents/src/outbound/pg_document_repo/legacy_upgrade.rs@@ -0,0 +1,113 @@+//! Persistence for swapping a legacy Office document to its OpenXML upgrade.++use entity_registry::BotFacts;+use model::document::FileType;++use crate::domain::content::DocumentContent;+use crate::domain::legacy_office_upgrade::LegacyOfficeUpgradeRepoPort;+use crate::domain::models::DocumentError;+use crate::domain::ports::DocumentRepo;++use super::PgDocumentRepo;++fn internal(error: sqlx::Error) -> DocumentError {+ DocumentError::Internal(error.into())+}++impl<B: BotFacts + 'static> LegacyOfficeUpgradeRepoPort for PgDocumentRepo<B> {+ #[tracing::instrument(err, skip(self))]+ async fn create_document_instance(+ &self,+ document_id: &str,+ sha: &str,+ ) -> Result<i64, DocumentError> {+ sqlx::query_scalar!(+ r#"+ INSERT INTO "DocumentInstance" ("documentId", "sha", "createdAt", "updatedAt")+ VALUES ($1, $2, NOW(), NOW())+ RETURNING id+ "#,+ document_id,+ sha,+ )+ .fetch_one(&self.pool)+ .await+ .map_err(internal)+ }++ #[tracing::instrument(err, skip(self))]+ async fn delete_document_instance(&self, version_id: i64) -> Result<(), DocumentError> {+ sqlx::query!(+ r#"DELETE FROM "DocumentInstance" WHERE id = $1"#,+ version_id,+ )+ .execute(&self.pool)+ .await+ .map_err(internal)?;+ Ok(())+ }++ #[tracing::instrument(err, skip(self))]+ async fn create_document_bom(&self, document_id: &str) -> Result<i64, DocumentError> {+ sqlx::query_scalar!(+ r#"+ INSERT INTO "DocumentBom" ("documentId", "createdAt", "updatedAt")+ VALUES ($1, NOW(), NOW())+ RETURNING id+ "#,+ document_id,+ )+ .fetch_one(&self.pool)+ .await+ .map_err(internal)+ }++ #[tracing::instrument(err, skip(self))]+ async fn delete_document_bom(&self, bom_id: i64) -> Result<(), DocumentError> {+ sqlx::query!(r#"DELETE FROM "DocumentBom" WHERE id = $1"#, bom_id)+ .execute(&self.pool)+ .await+ .map_err(internal)?;+ Ok(())+ }++ #[tracing::instrument(err, skip(self))]+ async fn swap_document_file_type(+ &self,+ document_id: &str,+ from: FileType,+ to: FileType,+ ) -> Result<bool, DocumentError> {+ // Stored file types can carry the upload's casing, so compare+ // case-insensitively and always write the canonical lowercase type.+ let result = sqlx::query!(+ r#"+ UPDATE "Document"+ SET "fileType" = $3,+ "updatedAt" = NOW()+ WHERE id = $1 AND LOWER("fileType") = $2+ "#,+ document_id,+ from.as_str(),+ to.as_str(),+ )+ .execute(&self.pool)+ .await+ .map_err(internal)?;+ Ok(result.rows_affected() == 1)+ }++ #[tracing::instrument(err, skip(self, content))]+ async fn set_document_content(+ &self,+ document_id: &str,+ content: DocumentContent,+ ) -> Result<(), DocumentError> {+ DocumentRepo::set_document_content(self, document_id, content)+ .await+ .map_err(internal)+ }+}++#[cfg(test)]+mod tests;diff --git a/crates/documents/src/outbound/pg_document_repo/legacy_upgrade/tests.rs b/crates/documents/src/outbound/pg_document_repo/legacy_upgrade/tests.rsnew file mode 100644index 0000000000..4160756fc9--- /dev/null+++ b/crates/documents/src/outbound/pg_document_repo/legacy_upgrade/tests.rs@@ -0,0 +1,205 @@+use entity_registry::{EntityRegistryResult, OwnerGrantPolicy};+use entity_registry_db_utils::OwnedEntityRegistrar;+use macro_db_migrator::MACRO_DB_MIGRATIONS;+use model_owner::Owner;+use sqlx::{Pool, Postgres};++use super::*;+use crate::domain::content::{DocumentContentLocation, DocumentContentState};++/// `txt` document with one instance in the fixture.+const DOCUMENT_ID: &str = "d0000000-0000-0000-0000-000000000001";++#[derive(Clone)]+struct NoBots;++impl BotFacts for NoBots {+ async fn sponsor(&self, _bot: bot_id::BotId) -> EntityRegistryResult<Option<Owner>> {+ Ok(None)+ }+}++fn repo(pool: Pool<Postgres>) -> PgDocumentRepo<NoBots> {+ PgDocumentRepo::new(+ pool,+ OwnedEntityRegistrar::new(OwnerGrantPolicy::new(NoBots)),+ )+}++async fn set_file_type(pool: &Pool<Postgres>, file_type: &str) {+ sqlx::query!(+ r#"UPDATE "Document" SET "fileType" = $2 WHERE id = $1"#,+ DOCUMENT_ID,+ file_type,+ )+ .execute(pool)+ .await+ .unwrap();+}++async fn file_type(pool: &Pool<Postgres>) -> Option<String> {+ sqlx::query_scalar!(+ r#"SELECT "fileType" FROM "Document" WHERE id = $1"#,+ DOCUMENT_ID+ )+ .fetch_one(pool)+ .await+ .unwrap()+}++#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../../../fixtures", scripts("documents_test_data"))+)]+async fn new_instance_becomes_the_latest_version(pool: Pool<Postgres>) {+ let repo = repo(pool.clone());+ let (before, _) = repo+ .get_latest_document_version_id(DOCUMENT_ID)+ .await+ .unwrap();++ let version_id = repo+ .create_document_instance(DOCUMENT_ID, "upgraded-sha")+ .await+ .unwrap();++ assert_ne!(version_id, before);+ let (latest, _) = repo+ .get_latest_document_version_id(DOCUMENT_ID)+ .await+ .unwrap();+ assert_eq!(latest, version_id);+ let sha = sqlx::query_scalar!(+ r#"SELECT sha FROM "DocumentInstance" WHERE id = $1"#,+ version_id+ )+ .fetch_one(&pool)+ .await+ .unwrap();+ assert_eq!(sha, "upgraded-sha");++ repo.delete_document_instance(version_id).await.unwrap();+ let (restored, _) = repo+ .get_latest_document_version_id(DOCUMENT_ID)+ .await+ .unwrap();+ assert_eq!(restored, before);+}++#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../../../fixtures", scripts("documents_test_data"))+)]+async fn bom_can_be_created_and_removed(pool: Pool<Postgres>) {+ let repo = repo(pool.clone());++ let bom_id = repo.create_document_bom(DOCUMENT_ID).await.unwrap();+ let count = || async {+ sqlx::query_scalar!(+ r#"SELECT COUNT(*) AS "count!" FROM "DocumentBom" WHERE id = $1 AND "documentId" = $2"#,+ bom_id,+ DOCUMENT_ID,+ )+ .fetch_one(&pool)+ .await+ .unwrap()+ };+ assert_eq!(count().await, 1);++ repo.delete_document_bom(bom_id).await.unwrap();+ assert_eq!(count().await, 0);+}++#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../../../fixtures", scripts("documents_test_data"))+)]+async fn swap_only_changes_the_expected_type(pool: Pool<Postgres>) {+ let repo = repo(pool.clone());+ set_file_type(&pool, "ppt").await;++ assert!(+ !repo+ .swap_document_file_type(DOCUMENT_ID, FileType::Doc, FileType::Docx)+ .await+ .unwrap()+ );+ assert_eq!(file_type(&pool).await.as_deref(), Some("ppt"));++ assert!(+ repo.swap_document_file_type(DOCUMENT_ID, FileType::Ppt, FileType::Pptx)+ .await+ .unwrap()+ );+ assert_eq!(file_type(&pool).await.as_deref(), Some("pptx"));++ // A second swap from the old type loses.+ assert!(+ !repo+ .swap_document_file_type(DOCUMENT_ID, FileType::Ppt, FileType::Pptx)+ .await+ .unwrap()+ );+}++#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../../../fixtures", scripts("documents_test_data"))+)]+async fn swap_matches_uppercase_stored_types(pool: Pool<Postgres>) {+ let repo = repo(pool.clone());+ set_file_type(&pool, "XLS").await;++ assert!(+ repo.swap_document_file_type(DOCUMENT_ID, FileType::Xls, FileType::Xlsx)+ .await+ .unwrap()+ );+ assert_eq!(file_type(&pool).await.as_deref(), Some("xlsx"));+}++#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../../../fixtures", scripts("documents_test_data"))+)]+async fn swap_on_a_missing_document_reports_no_change(pool: Pool<Postgres>) {+ let repo = repo(pool);++ assert!(+ !repo+ .swap_document_file_type(+ "d0000000-0000-0000-0000-00000000ffff",+ FileType::Doc,+ FileType::Docx+ )+ .await+ .unwrap()+ );+}++#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../../../fixtures", scripts("documents_test_data"))+)]+async fn content_is_persisted(pool: Pool<Postgres>) {+ let repo = repo(pool);++ LegacyOfficeUpgradeRepoPort::set_document_content(+ &repo,+ DOCUMENT_ID,+ DocumentContent::pending_at(DocumentContentLocation::ConvertedPdf),+ )+ .await+ .unwrap();++ let content = repo+ .get_persisted_document_content(DOCUMENT_ID)+ .await+ .unwrap()+ .unwrap();+ assert_eq!(content.state, DocumentContentState::Pending);+ assert_eq!(+ content.location,+ Some(DocumentContentLocation::ConvertedPdf)+ );+}diff --git a/crates/docx_engine/tests/fixtures/upgraded-from-doc.docx b/crates/docx_engine/tests/fixtures/upgraded-from-doc.docxnew file mode 100644index 0000000000..ec0a587011Binary files /dev/null and b/crates/docx_engine/tests/fixtures/upgraded-from-doc.docx differdiff --git a/crates/docx_engine/tests/upgraded_legacy.rs b/crates/docx_engine/tests/upgraded_legacy.rsnew file mode 100644index 0000000000..3f7485058f--- /dev/null+++ b/crates/docx_engine/tests/upgraded_legacy.rs@@ -0,0 +1,132 @@+//! A legacy `.doc` upgraded to `.docx` by LibreOffice, as the convert service+//! does on upload (`fixtures/upgraded-from-doc.docx`, from+//! `services/convert_service/fixtures/legacy/memo.doc`), opens, lays out,+//! renders, edits and saves in the engine.++use docx_engine::Document;+use docx_engine::edit::{EditOp, Pos, Session};+use docx_engine::model::block::{BlockId, BlockKind};+use docx_engine::render::{ImageCache, Renderer};+use pptx_engine::font::FontDb;++fn fonts() -> FontDb {+ let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../pptx_engine/fonts");+ let mut files: Vec<_> = std::fs::read_dir(&dir)+ .expect("the PPTX engine's fonts")+ .filter_map(|e| e.ok().map(|e| e.path()))+ .filter(|p| p.extension().is_some_and(|e| e == "ttf"))+ .collect();+ files.sort();+ let mut db = FontDb::new();+ for file in files {+ db.register(std::fs::read(file).expect("a font file"));+ }+ db+}++fn upgraded_bytes() -> Vec<u8> {+ std::fs::read(+ std::path::Path::new(env!("CARGO_MANIFEST_DIR"))+ .join("tests/fixtures/upgraded-from-doc.docx"),+ )+ .expect("the upgraded fixture")+}++/// Top-level paragraph texts of the body, in order.+fn paragraphs(document: &Document) -> Vec<(BlockId, String)> {+ let body = document.body();+ body.children(None)+ .iter()+ .filter_map(|id| body.get(id))+ .filter(|block| block.kind == BlockKind::Paragraph)+ .map(|block| (block.id.clone(), block.content.text()))+ .collect()+}++#[test]+fn upgraded_document_lays_out_and_renders() {+ let document = Document::open(upgraded_bytes()).expect("the upgraded document opens");+ let fonts = fonts();++ let layout = document.layout(&fonts);++ // The memo has a page break before its appendix.+ assert!(layout.pages.len() >= 2, "{} pages", layout.pages.len());+ let mut images = ImageCache::new();+ let mut renderer = Renderer {+ doc: &document,+ fonts: &fonts,+ images: &mut images,+ };+ for page in &layout.pages {+ let raster = renderer.render_page(page, 0.5);+ assert!(raster.width > 0);+ }+}++#[test]+fn paragraph_text_survives_the_upgrade() {+ let document = Document::open(upgraded_bytes()).unwrap();+ let texts: Vec<String> = paragraphs(&document).into_iter().map(|(_, t)| t).collect();+ let all = texts.join("\n");++ for expected in [+ "Quarterly Memo",+ "Revenue grew twelve percent quarter over quarter, with margins holding steady.",+ "Launched the new editor",+ "Closed three enterprise deals",+ "Appendix",+ "Café façade naïve – unicode survives the round trip.",+ ] {+ assert!(all.contains(expected), "missing {expected:?} in {texts:?}");+ }+ let xml = document.document_xml();+ assert!(xml.contains("<w:tbl>"), "table lost");+}++#[test]+fn upgraded_document_is_editable_and_saves() {+ let fonts = fonts();+ let document = Document::open(upgraded_bytes()).unwrap();+ let (title, _) = paragraphs(&document)+ .into_iter()+ .find(|(_, text)| text == "Quarterly Memo")+ .expect("the title paragraph");+ let mut editor = Session::new(document);++ let caret = Pos::new(title, 0);+ editor+ .apply(+ &[+ EditOp::Select {+ anchor: caret.clone(),+ focus: caret,+ },+ EditOp::InsertText {+ text: "Upgraded ".to_string(),+ },+ ],+ None,+ &fonts,+ )+ .expect("the title is editable");+ let saved = editor.save().expect("the edited document saves");++ let reopened = Document::open(saved).expect("the saved document reopens");+ assert!(+ paragraphs(&reopened)+ .iter()+ .any(|(_, text)| text == "Upgraded Quarterly Memo")+ );+}++#[test]+fn unedited_save_keeps_every_paragraph() {+ let document = Document::open(upgraded_bytes()).unwrap();+ let before: Vec<String> = paragraphs(&document).into_iter().map(|(_, t)| t).collect();++ let reopened = Document::open(document.save().unwrap()).unwrap();++ let after: Vec<String> = paragraphs(&reopened).into_iter().map(|(_, t)| t).collect();+ assert_eq!(before, after);+}diff --git a/crates/item_filters/src/ast/tests/other.json b/crates/item_filters/src/ast/tests/other.jsonindex fbf86a34b3..e12b78f539 100644--- a/crates/item_filters/src/ast/tests/other.json+++ b/crates/item_filters/src/ast/tests/other.json@@ -1 +1 @@-{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"l":{"ft":"jpeg"}},{"l":{"ft":"jpg"}}]},{"l":{"ft":"png"}}]},{"l":{"ft":"gif"}}]},{"l":{"ft":"svg"}}]},{"l":{"ft":"webp"}}]},{"l":{"ft":"avif"}}]},{"l":{"ft":"bmp"}}]},{"l":{"ft":"ico"}}]},{"l":{"ft":"tiff"}}]},{"l":{"ft":"tif"}}]},{"l":{"ft":"heic"}}]},{"l":{"ft":"heif"}}]},{"l":{"ft":"tar"}}]},{"l":{"ft":"targz"}}]},{"l":{"ft":"tgz"}}]},{"l":{"ft":"gz"}}]},{"l":{"ft":"bz2"}}]},{"l":{"ft":"tarbz2"}}]},{"l":{"ft":"tbz2"}}]},{"l":{"ft":"z"}}]},{"l":{"ft":"tarz"}}]},{"l":{"ft":"lz"}}]},{"l":{"ft":"tarlz"}}]},{"l":{"ft":"xz"}}]},{"l":{"ft":"tarxz"}}]},{"l":{"ft":"txz"}}]},{"l":{"ft":"lzma"}}]},{"l":{"ft":"tarlzma"}}]},{"l":{"ft":"rar"}}]},{"l":{"ft":"sevenz"}}]},{"l":{"ft":"zst"}}]},{"l":{"ft":"tarzst"}}]},{"l":{"ft":"tzst"}}]},{"l":{"ft":"zip"}}]},{"l":{"ft":"exe"}}]},{"l":{"ft":"msi"}}]},{"l":{"ft":"dll"}}]},{"l":{"ft":"bat"}}]},{"l":{"ft":"cmd"}}]},{"l":{"ft":"com"}}]},{"l":{"ft":"appimage"}}]},{"l":{"ft":"app"}}]},{"l":{"ft":"bin"}}]},{"l":{"ft":"deb"}}]},{"l":{"ft":"rpm"}}]},{"l":{"ft":"apk"}}]},{"l":{"ft":"dmg"}}]},{"l":{"ft":"pkg"}}]},{"l":{"ft":"crx"}}]},{"l":{"ft":"xpi"}}]},{"l":{"ft":"mp3"}}]},{"l":{"ft":"wav"}}]},{"l":{"ft":"ogg"}}]},{"l":{"ft":"flac"}}]},{"l":{"ft":"aac"}}]},{"l":{"ft":"m4a"}}]},{"l":{"ft":"wma"}}]},{"l":{"ft":"mid"}}]},{"l":{"ft":"midi"}}]},{"l":{"ft":"ttf"}}]},{"l":{"ft":"otf"}}]},{"l":{"ft":"woff"}}]},{"l":{"ft":"woff2"}}]},{"l":{"ft":"eot"}}]},{"l":{"ft":"rtf"}}]},{"l":{"ft":"odt"}}]},{"l":{"ft":"ods"}}]},{"l":{"ft":"odp"}}]},{"l":{"ft":"odg"}}]},{"l":{"ft":"odf"}}]},{"l":{"ft":"epub"}}]},{"l":{"ft":"mobi"}}]},{"l":{"ft":"azw"}}]},{"l":{"ft":"azw3"}}]},{"l":{"ft":"djvu"}}]},{"l":{"ft":"xls"}}]},{"l":{"ft":"ppt"}}]},{"l":{"ft":"pptx"}}]},{"l":{"ft":"xlsx"}}]},{"l":{"ft":"db"}}]},{"l":{"ft":"sqlite"}}]},{"l":{"ft":"sqlite3"}}]},{"l":{"ft":"mdb"}}]},{"l":{"ft":"accdb"}}]},{"l":{"ft":"dbf"}}]},{"l":{"ft":"plist"}}]},{"l":{"ft":"toml"}}]},{"l":{"ft":"env"}}]},{"l":{"ft":"dot"}}]},{"l":{"ft":"gv"}}]},{"l":{"ft":"torrent"}}]},{"l":{"ft":"ics"}}]},{"l":{"ft":"vcf"}}]},{"l":{"ft":"ai"}}]},{"l":{"ft":"eps"}}]},{"l":{"ft":"ps"}}]},{"l":{"ft":"dxf"}}]},{"l":{"ft":"dwg"}}]},{"l":{"ft":"fig"}}]},{"l":{"ft":"psd"}}]},{"l":{"ft":"psb"}}]},{"l":{"ft":"stl"}}]},{"l":{"ft":"obj"}}]},{"l":{"ft":"fbx"}}]},{"l":{"ft":"blend"}}]},{"l":{"ft":"dae"}}]},{"l":{"ft":"threeds"}}]},{"l":{"ft":"gltf"}}]},{"l":{"ft":"glb"}}]},{"l":{"ft":"vhd"}}]},{"l":{"ft":"vhdx"}}]},{"l":{"ft":"vmdk"}}]},{"l":{"ft":"ova"}}]},{"l":{"ft":"ovf"}}]},{"l":{"ft":"iso"}}]},{"l":{"ft":"img"}}]},{"l":{"ft":"swf"}}]}+{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"l":{"ft":"jpeg"}},{"l":{"ft":"jpg"}}]},{"l":{"ft":"png"}}]},{"l":{"ft":"gif"}}]},{"l":{"ft":"svg"}}]},{"l":{"ft":"webp"}}]},{"l":{"ft":"avif"}}]},{"l":{"ft":"bmp"}}]},{"l":{"ft":"ico"}}]},{"l":{"ft":"tiff"}}]},{"l":{"ft":"tif"}}]},{"l":{"ft":"heic"}}]},{"l":{"ft":"heif"}}]},{"l":{"ft":"tar"}}]},{"l":{"ft":"targz"}}]},{"l":{"ft":"tgz"}}]},{"l":{"ft":"gz"}}]},{"l":{"ft":"bz2"}}]},{"l":{"ft":"tarbz2"}}]},{"l":{"ft":"tbz2"}}]},{"l":{"ft":"z"}}]},{"l":{"ft":"tarz"}}]},{"l":{"ft":"lz"}}]},{"l":{"ft":"tarlz"}}]},{"l":{"ft":"xz"}}]},{"l":{"ft":"tarxz"}}]},{"l":{"ft":"txz"}}]},{"l":{"ft":"lzma"}}]},{"l":{"ft":"tarlzma"}}]},{"l":{"ft":"rar"}}]},{"l":{"ft":"sevenz"}}]},{"l":{"ft":"zst"}}]},{"l":{"ft":"tarzst"}}]},{"l":{"ft":"tzst"}}]},{"l":{"ft":"zip"}}]},{"l":{"ft":"exe"}}]},{"l":{"ft":"msi"}}]},{"l":{"ft":"dll"}}]},{"l":{"ft":"bat"}}]},{"l":{"ft":"cmd"}}]},{"l":{"ft":"com"}}]},{"l":{"ft":"appimage"}}]},{"l":{"ft":"app"}}]},{"l":{"ft":"bin"}}]},{"l":{"ft":"deb"}}]},{"l":{"ft":"rpm"}}]},{"l":{"ft":"apk"}}]},{"l":{"ft":"dmg"}}]},{"l":{"ft":"pkg"}}]},{"l":{"ft":"crx"}}]},{"l":{"ft":"xpi"}}]},{"l":{"ft":"mp3"}}]},{"l":{"ft":"wav"}}]},{"l":{"ft":"ogg"}}]},{"l":{"ft":"flac"}}]},{"l":{"ft":"aac"}}]},{"l":{"ft":"m4a"}}]},{"l":{"ft":"wma"}}]},{"l":{"ft":"mid"}}]},{"l":{"ft":"midi"}}]},{"l":{"ft":"ttf"}}]},{"l":{"ft":"otf"}}]},{"l":{"ft":"woff"}}]},{"l":{"ft":"woff2"}}]},{"l":{"ft":"eot"}}]},{"l":{"ft":"rtf"}}]},{"l":{"ft":"odt"}}]},{"l":{"ft":"ods"}}]},{"l":{"ft":"odp"}}]},{"l":{"ft":"odg"}}]},{"l":{"ft":"odf"}}]},{"l":{"ft":"epub"}}]},{"l":{"ft":"mobi"}}]},{"l":{"ft":"azw"}}]},{"l":{"ft":"azw3"}}]},{"l":{"ft":"djvu"}}]},{"l":{"ft":"xls"}}]},{"l":{"ft":"xlsm"}}]},{"l":{"ft":"ppt"}}]},{"l":{"ft":"doc"}}]},{"l":{"ft":"pptx"}}]},{"l":{"ft":"xlsx"}}]},{"l":{"ft":"db"}}]},{"l":{"ft":"sqlite"}}]},{"l":{"ft":"sqlite3"}}]},{"l":{"ft":"mdb"}}]},{"l":{"ft":"accdb"}}]},{"l":{"ft":"dbf"}}]},{"l":{"ft":"plist"}}]},{"l":{"ft":"toml"}}]},{"l":{"ft":"env"}}]},{"l":{"ft":"dot"}}]},{"l":{"ft":"gv"}}]},{"l":{"ft":"torrent"}}]},{"l":{"ft":"ics"}}]},{"l":{"ft":"vcf"}}]},{"l":{"ft":"ai"}}]},{"l":{"ft":"eps"}}]},{"l":{"ft":"ps"}}]},{"l":{"ft":"dxf"}}]},{"l":{"ft":"dwg"}}]},{"l":{"ft":"fig"}}]},{"l":{"ft":"psd"}}]},{"l":{"ft":"psb"}}]},{"l":{"ft":"stl"}}]},{"l":{"ft":"obj"}}]},{"l":{"ft":"fbx"}}]},{"l":{"ft":"blend"}}]},{"l":{"ft":"dae"}}]},{"l":{"ft":"threeds"}}]},{"l":{"ft":"gltf"}}]},{"l":{"ft":"glb"}}]},{"l":{"ft":"vhd"}}]},{"l":{"ft":"vhdx"}}]},{"l":{"ft":"vmdk"}}]},{"l":{"ft":"ova"}}]},{"l":{"ft":"ovf"}}]},{"l":{"ft":"iso"}}]},{"l":{"ft":"img"}}]},{"l":{"ft":"swf"}}]}diff --git a/crates/model/src/convert.rs b/crates/model/src/convert.rsindex d9cbc46f8e..167082bfc7 100644--- a/crates/model/src/convert.rs+++ b/crates/model/src/convert.rs@@ -1,6 +1,8 @@use serde::{Deserialize, Serialize};use utoipa::ToSchema;+use crate::document::FileType;+#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]pub struct ConvertRequest {/// The bucket of the current item@@ -26,4 +28,11 @@ pub struct ConvertQueueMessage {pub from_key: String,/// The destination key of the current item we are convertingpub to_key: String,+ /// The source file type, for keys without an extension such as+ /// versioned document keys. Falls back to the `from_key` extension.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub from_file_type: Option<FileType>,+ /// The target file type. Falls back to the `to_key` extension.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub to_file_type: Option<FileType>,}diff --git a/crates/model/src/document/file_type/tests.rs b/crates/model/src/document/file_type/tests.rsindex 32e6398d2a..92e4ec7081 100644--- a/crates/model/src/document/file_type/tests.rs+++ b/crates/model/src/document/file_type/tests.rs@@ -157,6 +157,24 @@ fn test_split_suffix_match() {);}+#[test]+fn test_split_suffix_match_office_files() {+ for (file_name, expected) in [+ ("Budget.xlsm", Some(("Budget", "xlsm"))),+ ("Old Memo.doc", Some(("Old Memo", "doc"))),+ ("OLD MEMO.DOC", Some(("OLD MEMO", "DOC"))),+ ("Deck.ppt", Some(("Deck", "ppt"))),+ ("Ledger.xls", Some(("Ledger", "xls"))),+ ("notes.mdoc", Some(("notes", "mdoc"))),+ ] {+ assert_eq!(+ FileType::split_suffix_match(file_name),+ expected,+ "{file_name}"+ );+ }+}+#[test]fn design_files_are_editable_documents_not_images() {for file_type in [FileType::Psd, FileType::Psb, FileType::Ai, FileType::Fig] {diff --git a/crates/model/src/folder.rs b/crates/model/src/folder.rsindex 72495ebe45..c824492cec 100644--- a/crates/model/src/folder.rs+++ b/crates/model/src/folder.rs@@ -29,6 +29,11 @@ pub struct UploadFolderRequest {/// Optional parent project id to upload the folder into#[serde(skip_serializing_if = "Option::is_none")]pub parent_id: Option<String>,+ /// Relative paths of folders to create even when they hold no files.+ ///+ /// Uses the same shape as [FolderItem::relative_path], root folder included.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub folders: Vec<String>,}pub struct UploadFolderWithIdsResponse {@@ -95,12 +100,23 @@ impl FileSystemNode {pub fn build_file_system(root_folder_name: &str,content: Vec<FolderItem>,+ folders: &[String],) -> anyhow::Result<FileSystemNode> {let mut root = FileSystemNode::Folder(HashMap::from([(root_folder_name.to_string(),FileSystemNode::Folder(HashMap::new()),)]));+ for folder in folders {+ let mut current_node = &mut root;+ for component in folder.split('/').filter(|s| !s.is_empty()) {+ current_node = current_node+ .as_folder_mut()?+ .entry(component.to_string())+ .or_insert_with(|| FileSystemNode::Folder(HashMap::new()));+ }+ }+for item in content {// Split the relative_path into components, including the root folder namelet mut path_components: Vec<&str> = itemdiff --git a/crates/model_file_type/src/lib.rs b/crates/model_file_type/src/lib.rsindex ae202c42ad..5ede92a222 100644--- a/crates/model_file_type/src/lib.rs+++ b/crates/model_file_type/src/lib.rs@@ -157,19 +157,16 @@ macro_rules! generate_file_types {impl FromStr for ContentType {type Err = ValueError<Self>;fn from_str(mime_type: &str) -> Result<Self, Self::Err> {- let cleaned = mime_type.to_ascii_lowercase();-- // there can be multiple variants for the same mime type- // but it does not matter for the purposes of this function- #[expect(unreachable_patterns)]- match cleaned.as_str() {- $(- $mime_type => Ok(ContentType::$variant),- )*- _ => {- Err(ValueError(cleaned, PhantomData))+ // MIME types are case-insensitive, and some canonical ones are+ // mixed case (`application/vnd.ms-excel.sheet.macroEnabled.12`).+ // There can be multiple variants for the same mime type; the+ // first one wins, which does not matter for this function.+ $(+ if mime_type.eq_ignore_ascii_case($mime_type) {+ return Ok(ContentType::$variant);}- }+ )*+ Err(ValueError(mime_type.to_ascii_lowercase(), PhantomData))}}@@ -697,7 +694,14 @@ generate_file_types!((Azw3, "azw3", "application/vnd.amazon.ebook", Document),(Djvu, "djvu", "image/vnd.djvu", Document),(Xls, "xls", "application/vnd.ms-excel", Document),+ (+ Xlsm,+ "xlsm",+ "application/vnd.ms-excel.sheet.macroEnabled.12",+ Document+ ),(Ppt, "ppt", "application/vnd.ms-powerpoint", Document),+ (Doc, "doc", "application/msword", Document),(Pptx, "pptx", "application/xml", Document),(Xlsx, "xlsx", "application/xml", Document),// Database filesdiff --git a/crates/model_file_type/src/test.rs b/crates/model_file_type/src/test.rsindex 7792b3e5a4..d4a54233fd 100644--- a/crates/model_file_type/src/test.rs+++ b/crates/model_file_type/src/test.rs@@ -15,6 +15,77 @@ fn native_spreadsheet_extension_and_content_type_round_trip() {assert_ne!(FileType::from_str("csv").unwrap(), file_type);}+#[test]+fn office_extensions_parse_case_insensitively() {+ for (extension, expected) in [+ ("docx", FileType::Docx),+ ("DOCX", FileType::Docx),+ ("doc", FileType::Doc),+ ("DOC", FileType::Doc),+ ("pptx", FileType::Pptx),+ ("Pptx", FileType::Pptx),+ ("ppt", FileType::Ppt),+ ("xlsx", FileType::Xlsx),+ ("XLSX", FileType::Xlsx),+ ("xls", FileType::Xls),+ ("xlsm", FileType::Xlsm),+ ("XLSM", FileType::Xlsm),+ ] {+ assert_eq!(+ FileType::from_str(extension).unwrap(),+ expected,+ "{extension}"+ );+ }+}++#[test]+fn legacy_office_types_round_trip() {+ for (file_type, extension, mime) in [+ (FileType::Doc, "doc", "application/msword"),+ (+ FileType::Xlsm,+ "xlsm",+ "application/vnd.ms-excel.sheet.macroEnabled.12",+ ),+ ] {+ assert_eq!(file_type.as_str(), extension);+ assert_eq!(file_type.mime_type(), mime);+ assert_eq!(file_type.macro_app_path().to_string(), "document");+ assert_eq!(FileType::from_str(extension).unwrap(), file_type);+ assert_eq!(+ serde_json::to_string(&file_type).unwrap(),+ format!("\"{extension}\"")+ );+ }+}++#[test]+fn every_mime_type_parses_back_to_a_content_type() {+ for file_type in FileType::all() {+ let content_type = ContentType::from_str(file_type.mime_type())+ .unwrap_or_else(|e| panic!("{file_type}: {e}"));+ assert_eq!(content_type.mime_type(), file_type.mime_type());+ }+}++#[test]+fn mime_types_parse_case_insensitively() {+ assert_eq!(+ ContentType::from_str("application/vnd.ms-excel.sheet.macroEnabled.12").unwrap(),+ ContentType::from(FileType::Xlsm)+ );+ assert_eq!(+ ContentType::from_str("APPLICATION/VND.MS-EXCEL.SHEET.MACROENABLED.12").unwrap(),+ ContentType::from(FileType::Xlsm)+ );+ assert_eq!(+ ContentType::from_str("Application/MSWord").unwrap(),+ ContentType::from(FileType::Doc)+ );+ assert!(ContentType::from_str("application/x-not-a-type").is_err());+}+#[test]fn photoshop_documents_are_design_files_not_images() {for (extension, file_type) in [("psd", FileType::Psd), (".PSB", FileType::Psb)] {diff --git a/crates/pptx_engine/tests/fixtures/upgraded-from-ppt.pptx b/crates/pptx_engine/tests/fixtures/upgraded-from-ppt.pptxnew file mode 100644index 0000000000..3c7b711edbBinary files /dev/null and b/crates/pptx_engine/tests/fixtures/upgraded-from-ppt.pptx differdiff --git a/crates/pptx_engine/tests/upgraded_legacy.rs b/crates/pptx_engine/tests/upgraded_legacy.rsnew file mode 100644index 0000000000..321397c651--- /dev/null+++ b/crates/pptx_engine/tests/upgraded_legacy.rs@@ -0,0 +1,115 @@+//! A legacy `.ppt` deck upgraded to `.pptx` by LibreOffice, as the convert+//! service does on upload (`fixtures/upgraded-from-ppt.pptx`, from+//! `services/convert_service/fixtures/legacy/deck.ppt`), opens, renders, edits+//! and saves in the engine.++use pptx_engine::font::FontDb;+use pptx_engine::{EditOp, Presentation};++fn fonts() -> FontDb {+ let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fonts");+ let mut files: Vec<_> = std::fs::read_dir(&dir)+ .expect("the fonts directory")+ .filter_map(|e| e.ok().map(|e| e.path()))+ .filter(|p| {+ p.extension()+ .is_some_and(|e| e.eq_ignore_ascii_case("ttf") || e.eq_ignore_ascii_case("otf"))+ })+ .collect();+ files.sort();+ let mut db = FontDb::new();+ for file in files {+ db.register(std::fs::read(file).expect("a font file"));+ }+ db+}++fn upgraded_deck() -> Presentation {+ let bytes = std::fs::read(+ std::path::Path::new(env!("CARGO_MANIFEST_DIR"))+ .join("tests/fixtures/upgraded-from-ppt.pptx"),+ )+ .expect("the upgraded fixture");+ Presentation::open(bytes).expect("the upgraded deck opens")+}++fn slide_xml(presentation: &Presentation, index: usize) -> String {+ let part = presentation.slides()[index].part.clone();+ String::from_utf8(presentation.read_bytes(&part).unwrap()).unwrap()+}++/// The `p:cNvPr` id of the shape whose text contains `needle`.+fn shape_id_with_text(xml: &str, needle: &str) -> u32 {+ let at = xml.find(needle).expect("text on the slide");+ let tag = xml[..at]+ .rfind("<p:cNvPr id=\"")+ .expect("a shape before the text");+ let rest = &xml[tag + "<p:cNvPr id=\"".len()..];+ rest[..rest.find('"').unwrap()].parse().unwrap()+}++#[test]+fn every_slide_renders() {+ let mut presentation = upgraded_deck();+ let fonts = fonts();++ assert_eq!(presentation.slides().len(), 4);+ for index in 0..presentation.slides().len() {+ let raster = presentation+ .render_slide(index, 320, &fonts)+ .unwrap_or_else(|e| panic!("slide {} failed to render: {e}", index + 1));+ assert_eq!(raster.width, 320);+ }+}++#[test]+fn slide_content_survives_the_upgrade() {+ let presentation = upgraded_deck();++ assert!(slide_xml(&presentation, 0).contains("Board Update"));+ let highlights = slide_xml(&presentation, 1);+ assert!(highlights.contains("Revenue up 12%"));+ assert!(highlights.contains("Three new customers"));+ assert!(slide_xml(&presentation, 2).contains("<a:tbl>"));+ let shapes = slide_xml(&presentation, 3);+ assert!(shapes.contains("Shape text"));+ assert!(shapes.contains("<p:pic>"), "picture lost");+}++#[test]+fn upgraded_deck_is_editable_and_saves() {+ let mut presentation = upgraded_deck();+ let fonts = fonts();+ let slide = presentation.slides()[0].id;+ let shape = shape_id_with_text(&slide_xml(&presentation, 0), "Board Update");++ presentation+ .apply(+ &[EditOp::SetText {+ slide,+ shape,+ cell: None,+ text: "Board Update (edited)".to_string(),+ }],+ &fonts,+ )+ .expect("the title is editable");+ let saved = presentation.save().expect("the edited deck saves");++ let mut reopened = Presentation::open(saved).expect("the saved deck reopens");+ assert!(slide_xml(&reopened, 0).contains("Board Update (edited)"));+ reopened+ .render_slide(0, 320, &fonts)+ .expect("the edited slide renders");+}++#[test]+fn unedited_save_keeps_the_upgrade() {+ let mut presentation = upgraded_deck();+ let before: Vec<String> = (0..4).map(|i| slide_xml(&presentation, i)).collect();++ let reopened = Presentation::open(presentation.save().unwrap()).unwrap();++ let after: Vec<String> = (0..4).map(|i| slide_xml(&reopened, i)).collect();+ assert_eq!(before, after);+}diff --git a/crates/projects/src/domain/service.rs b/crates/projects/src/domain/service.rsindex 80f9122959..7c1b7e4eff 100644--- a/crates/projects/src/domain/service.rs+++ b/crates/projects/src/domain/service.rs@@ -661,7 +661,7 @@ wherelet event_owner = actor.clone();let event_name = args.root_folder_name.clone();let event_parent_project_id = args.parent_id.clone();- let root_folder = build_root_folder(&args.root_folder_name, args.content)+ let root_folder = build_root_folder(&args.root_folder_name, args.content, &args.folders).map_err(|error| internal_error(error, "unable to prepare folder upload"))?;// The uploaded projects and documents all share the owner's team-deriveddiff --git a/crates/projects/src/domain/service/tests.rs b/crates/projects/src/domain/service/tests.rsindex 5c24414fd8..703e371931 100644--- a/crates/projects/src/domain/service/tests.rs+++ b/crates/projects/src/domain/service/tests.rs@@ -2181,6 +2181,7 @@ async fn upload_folder_publishes_uploaded_event() {root_folder_name: "Uploaded tree".to_string(),upload_request_id: "request".to_string(),parent_id: Some("parent-project".to_string()),+ folders: Vec::new(),},).await@@ -2235,6 +2236,7 @@ async fn upload_folder_with_no_project_ids_publishes_no_event() {root_folder_name: "Uploaded tree".to_string(),upload_request_id: "request".to_string(),parent_id: None,+ folders: Vec::new(),},).await@@ -2294,6 +2296,7 @@ async fn upload_folder_compensates_after_destination_failure() {root_folder_name: "Upload".to_string(),upload_request_id: "request".to_string(),parent_id: None,+ folders: Vec::new(),},).await;diff --git a/crates/projects/src/domain/upload.rs b/crates/projects/src/domain/upload.rsindex be83b70d2f..4838b2f893 100644--- a/crates/projects/src/domain/upload.rs+++ b/crates/projects/src/domain/upload.rs@@ -15,8 +15,9 @@ use super::ports::ProjectUploadUrlPort;pub fn build_root_folder(root_folder_name: &str,content: Vec<FolderItem>,+ folders: &[String],) -> anyhow::Result<FileSystemNode> {- let file_system = FileSystemNode::build_file_system(root_folder_name, content)?;+ let file_system = FileSystemNode::build_file_system(root_folder_name, content, folders)?;let FileSystemNode::Folder(mut roots) = file_system else {anyhow::bail!("expected folder upload to produce a folder root");};@@ -86,3 +87,112 @@ pub async fn build_destination_map<U: ProjectUploadUrlPort>(Ok(destinations)}++#[cfg(test)]+mod tests {+ use super::*;+ use model::document::FileTypeExt;++ fn item(relative_path: &str, full_name: &str) -> FolderItem {+ let (name, file_type) = match FileType::split_suffix_match(full_name) {+ Some((name, extension)) => (name, FileType::from_str(extension).ok()),+ None => (full_name, None),+ };+ FolderItem {+ name: name.to_string(),+ full_name: full_name.to_string(),+ file_type,+ relative_path: relative_path.to_string(),+ sha: "sha".to_string(),+ }+ }++ fn folder(node: &FileSystemNode) -> &std::collections::HashMap<String, FileSystemNode> {+ match node {+ FileSystemNode::Folder(content) => content,+ FileSystemNode::File(item) => panic!("expected folder, found {item:?}"),+ }+ }++ #[test]+ fn nested_files_build_nested_folders() {+ let root = build_root_folder(+ "Pack",+ vec![+ item("Pack", "Summary.docx"),+ item("Pack/Finance/Forecasts", "Q4.xlsx"),+ item("Pack/Decks/Archive", "Old.pptx"),+ ],+ &[],+ )+ .unwrap();++ let root = folder(&root);+ assert!(matches!(+ root.get("Summary.docx"),+ Some(FileSystemNode::File(_))+ ));+ let forecasts = folder(folder(&root["Finance"]).get("Forecasts").unwrap());+ assert!(matches!(+ forecasts.get("Q4.xlsx"),+ Some(FileSystemNode::File(_))+ ));+ let archive = folder(folder(&root["Decks"]).get("Archive").unwrap());+ assert!(matches!(+ archive.get("Old.pptx"),+ Some(FileSystemNode::File(_))+ ));+ }++ #[test]+ fn empty_folders_are_kept() {+ let root = build_root_folder(+ "Pack",+ vec![item("Pack/Finance", "Budget.xlsx")],+ &[+ "Pack".to_string(),+ "Pack/Empty".to_string(),+ "Pack/Finance".to_string(),+ "Pack/Finance/Empty Leaf".to_string(),+ ],+ )+ .unwrap();++ let root = folder(&root);+ assert!(folder(&root["Empty"]).is_empty());+ let finance = folder(&root["Finance"]);+ assert!(matches!(+ finance.get("Budget.xlsx"),+ Some(FileSystemNode::File(_))+ ));+ assert!(folder(&finance["Empty Leaf"]).is_empty());+ }++ #[test]+ fn folder_listed_before_its_files_keeps_the_files() {+ let root = build_root_folder(+ "Pack",+ vec![item("Pack/A", "a.docx")],+ &["Pack/A".to_string(), "Pack/A/B".to_string()],+ )+ .unwrap();++ let a = folder(&folder(&root)["A"]);+ assert_eq!(a.len(), 2);+ assert!(matches!(a.get("a.docx"), Some(FileSystemNode::File(_))));+ assert!(folder(&a["B"]).is_empty());+ }++ #[test]+ fn root_with_only_empty_folders() {+ let root = build_root_folder("Pack", Vec::new(), &["Pack/Only".to_string()]).unwrap();+ assert!(folder(&folder(&root)["Only"]).is_empty());+ }++ #[test]+ fn uppercase_extension_is_typed() {+ let upper = item("Pack", "REPORT.DOCX");+ assert_eq!(upper.file_type, Some(FileType::Docx));+ assert_eq!(upper.name, "REPORT");+ }+}diff --git a/crates/s3_key/src/document_key.rs b/crates/s3_key/src/document_key.rsindex a973746453..9079c8c82d 100644--- a/crates/s3_key/src/document_key.rs+++ b/crates/s3_key/src/document_key.rs@@ -17,11 +17,49 @@ pub const PDF_EXTENSION: &str = "pdf";/// The file extension for DOCX files.pub const DOCX_EXTENSION: &str = "docx";+/// The file name used for legacy Office files upgraded to their OpenXML+/// equivalents (`.doc` → `upgraded.docx`, `.ppt` → `upgraded.pptx`,+/// `.xls` → `upgraded.xlsx`).+pub const UPGRADED_DOCUMENT_FILE_NAME: &str = "upgraded";++/// The OpenXML format a legacy Office document is upgraded to.+#[derive(Eq, PartialEq, Debug, Clone, Copy)]+pub enum UpgradedOfficeFormat {+ /// Word, upgraded from `.doc`.+ Docx,+ /// PowerPoint, upgraded from `.ppt`.+ Pptx,+ /// Excel, upgraded from `.xls`.+ Xlsx,+}++impl UpgradedOfficeFormat {+ /// The file extension of the upgraded format.+ pub fn extension(self) -> &'static str {+ match self {+ Self::Docx => DOCX_EXTENSION,+ Self::Pptx => "pptx",+ Self::Xlsx => "xlsx",+ }+ }++ fn from_extension(extension: &str) -> Option<Self> {+ match extension {+ DOCX_EXTENSION => Some(Self::Docx),+ "pptx" => Some(Self::Pptx),+ "xlsx" => Some(Self::Xlsx),+ _ => None,+ }+ }+}+/// Represents an S3 key in the document storage bucket.////// Covers all known key shapes:/// - `Versioned`: `{owner}/{document_id}/{version_id}` — a specific document version/// - `ConvertedPdf`: `{owner}/{document_id}/converted.pdf` — a DOCX converted to PDF+/// - `UpgradedOffice`: `{owner}/{document_id}/upgraded.{docx|pptx|xlsx}` — a legacy+/// Office file converted to OpenXML/// - `TempDocx`: `temp_files/{document_id}.docx` — a temporary DOCX export/// - `SyncServiceSnapshot`: `sync_service_snapshot/{document_id}` — a cached CRDT snapshot/// - `BomPart`: `{sha}` — a content-addressable BOM part from DOCX uploads@@ -46,6 +84,16 @@ pub enum DocumentKey {/// The document ID.document_id: String,},+ /// A legacy Office file upgraded to OpenXML:+ /// `{owner}/{document_id}/upgraded.{docx|pptx|xlsx}`+ UpgradedOffice {+ /// The owner segment, an owner principal string.+ owner_segment: String,+ /// The document ID.+ document_id: String,+ /// The upgraded format.+ format: UpgradedOfficeFormat,+ },/// A temporary DOCX export: `temp_files/{document_id}.docx`TempDocx {/// The document ID.@@ -126,11 +174,21 @@ impl DocumentKey {let converted_pdf_suffix =format!("{CONVERTED_DOCUMENT_FILE_NAME}.{PDF_EXTENSION}");+ let upgraded_format = tail+ .strip_prefix(UPGRADED_DOCUMENT_FILE_NAME)+ .and_then(|rest| rest.strip_prefix('.'))+ .and_then(UpgradedOfficeFormat::from_extension);if tail == converted_pdf_suffix {Ok(Self::ConvertedPdf {owner_segment,document_id,})+ } else if let Some(format) = upgraded_format {+ Ok(Self::UpgradedOffice {+ owner_segment,+ document_id,+ format,+ })} else {let version_id: i64 = tail.parse().context(format!("invalid version id: expected integer, got '{tail}'"@@ -156,6 +214,7 @@ impl DocumentKey {match self {Self::Versioned { document_id, .. }| Self::ConvertedPdf { document_id, .. }+ | Self::UpgradedOffice { document_id, .. }| Self::TempDocx { document_id }| Self::SyncServiceSnapshot { document_id } => Some(document_id),Self::BomPart { .. } => None,@@ -165,9 +224,9 @@ impl DocumentKey {/// Returns the owner segment for the key shapes that carry one.pub fn owner_segment(&self) -> Option<&str> {match self {- Self::Versioned { owner_segment, .. } | Self::ConvertedPdf { owner_segment, .. } => {- Some(owner_segment)- }+ Self::Versioned { owner_segment, .. }+ | Self::ConvertedPdf { owner_segment, .. }+ | Self::UpgradedOffice { owner_segment, .. } => Some(owner_segment),Self::TempDocx { .. } | Self::SyncServiceSnapshot { .. } | Self::BomPart { .. } => None,}}@@ -197,6 +256,11 @@ impl DocumentKey {matches!(self, Self::ConvertedPdf { .. })}+ /// Returns `true` if this is an upgraded legacy Office key.+ pub fn is_upgraded_office(&self) -> bool {+ matches!(self, Self::UpgradedOffice { .. })+ }+/// Returns the version ID as a string suitable for `SearchExtractorMessage`.////// - `Versioned` → the integer version ID as a string@@ -206,7 +270,10 @@ impl DocumentKey {match self {Self::Versioned { version_id, .. } => Some(version_id.to_string()),Self::ConvertedPdf { .. } => Some(CONVERTED_DOCUMENT_FILE_NAME.to_string()),- Self::TempDocx { .. } | Self::SyncServiceSnapshot { .. } | Self::BomPart { .. } => None,+ Self::UpgradedOffice { .. }+ | Self::TempDocx { .. }+ | Self::SyncServiceSnapshot { .. }+ | Self::BomPart { .. } => None,}}@@ -227,6 +294,16 @@ impl DocumentKey {CONVERTED_DOCUMENT_FILE_NAME,Some(PDF_EXTENSION),),+ Self::UpgradedOffice {+ owner_segment,+ document_id,+ format,+ } => build_document_key_from_segment(+ owner_segment,+ document_id,+ UPGRADED_DOCUMENT_FILE_NAME,+ Some(format.extension()),+ ),Self::TempDocx { document_id } => build_temp_docx_key(document_id),Self::SyncServiceSnapshot { document_id } => {format!("{SYNC_SERVICE_SNAPSHOT_PREFIX}/{document_id}")@@ -293,6 +370,21 @@ pub fn build_docx_to_pdf_converted_document_key(owner: &Owner, document_id: &str)}+/// Builds the S3 key a legacy Office document's OpenXML upgrade is written to.+/// Format: `{owner}/{document_id}/upgraded.{docx|pptx|xlsx}`+pub fn build_upgraded_office_document_key(+ owner: &Owner,+ document_id: &str,+ format: UpgradedOfficeFormat,+) -> String {+ build_document_key_from_segment(+ &owner_segment(owner),+ document_id,+ UPGRADED_DOCUMENT_FILE_NAME,+ Some(format.extension()),+ )+}+/// Builds the S3 key for a DOCX document's staging bucket./// Format: `{owner}/{document_id}/{document_version_id}.docx`pub fn build_docx_staging_bucket_document_key(diff --git a/crates/s3_key/src/document_key/test.rs b/crates/s3_key/src/document_key/test.rsindex 4bc075214e..2bfbea3573 100644--- a/crates/s3_key/src/document_key/test.rs+++ b/crates/s3_key/src/document_key/test.rs@@ -340,3 +340,50 @@ fn test_build_temp_docx_key() {let key = build_temp_docx_key("document-id");assert_eq!(key, "temp_files/document-id.docx");}++#[test]+fn upgraded_office_keys_build_and_parse() {+ for (format, extension) in [+ (UpgradedOfficeFormat::Docx, "docx"),+ (UpgradedOfficeFormat::Pptx, "pptx"),+ (UpgradedOfficeFormat::Xlsx, "xlsx"),+ ] {+ for (principal, owner) in owners() {+ let key = build_upgraded_office_document_key(&owner, DOCUMENT_ID, format);+ assert_eq!(+ key,+ format!("{principal}/{DOCUMENT_ID}/upgraded.{extension}")+ );++ let parsed = DocumentKey::from_s3_key(&key).unwrap();+ assert_eq!(+ parsed,+ DocumentKey::UpgradedOffice {+ owner_segment: principal.to_string(),+ document_id: DOCUMENT_ID.to_string(),+ format,+ }+ );+ assert!(parsed.is_upgraded_office());+ assert!(!parsed.is_versioned());+ assert_eq!(parsed.document_id(), Some(DOCUMENT_ID));+ assert_eq!(parsed.owner_segment(), Some(principal));+ assert_eq!(parsed.version_id_string(), None);+ assert_eq!(parsed.to_key(), key);+ }+ }+}++#[test]+fn upgraded_office_keys_reject_other_extensions() {+ for tail in [+ "upgraded.doc",+ "upgraded.pdf",+ "upgraded",+ "upgraded.DOCX",+ "upgradedx.docx",+ ] {+ let key = format!("{USER_PRINCIPAL}/{DOCUMENT_ID}/{tail}");+ assert!(DocumentKey::from_s3_key(&key).is_err(), "{key}");+ }+}diff --git a/crates/s3_key/src/lib.rs b/crates/s3_key/src/lib.rsindex d33db193f3..a0f6f7a8ce 100644--- a/crates/s3_key/src/lib.rs+++ b/crates/s3_key/src/lib.rs@@ -5,9 +5,11 @@mod document_key;pub use document_key::{CONVERTED_DOCUMENT_FILE_NAME, DOCX_EXTENSION, DocumentKey, PDF_EXTENSION,- SYNC_SERVICE_SNAPSHOT_PREFIX, TEMP_FILE_PREFIX, build_cloud_storage_bucket_document_key,+ SYNC_SERVICE_SNAPSHOT_PREFIX, TEMP_FILE_PREFIX, UPGRADED_DOCUMENT_FILE_NAME,+ UpgradedOfficeFormat, build_cloud_storage_bucket_document_key,build_cloud_storage_bucket_document_prefix, build_docx_staging_bucket_document_key,- build_docx_to_pdf_converted_document_key, build_temp_docx_key, document_key_url_path,+ build_docx_to_pdf_converted_document_key, build_temp_docx_key,+ build_upgraded_office_document_key, document_key_url_path,};mod bulk_upload_key;pub use bulk_upload_key::BulkUploadStagingKey;diff --git a/crates/soup_filter_cache_adapter/src/test/file_type.rs b/crates/soup_filter_cache_adapter/src/test/file_type.rsindex 2d7b521a8e..6d41270e52 100644--- a/crates/soup_filter_cache_adapter/src/test/file_type.rs+++ b/crates/soup_filter_cache_adapter/src/test/file_type.rs@@ -407,7 +407,7 @@ fn malformed_file_type_data_is_still_rejected_but_unknown_filter_inputs_are_not_);assert!(compile_current_filter_request(- filters(json!({"literal":{"fileType":"doc"}})),+ filters(json!({"literal":{"fileType":"docm"}})),"UPDATED_AT","DESC",20diff --git a/docs/AGENT_GUIDE/documents.md b/docs/AGENT_GUIDE/documents.mdindex 85f7ddc540..721882c7b4 100644--- a/docs/AGENT_GUIDE/documents.md+++ b/docs/AGENT_GUIDE/documents.md@@ -96,7 +96,7 @@ the panel beneath the formatting and formula bars. While a workbook opens, ashimmering placeholder grid (status "Opening spreadsheet…") stands in for it, andformula cells show a short shimmer bar until their first results arrive; wait forreal cell text before reading values. They have the `.spreadsheet` file type; uploading an-Excel or CSV file in Files or a channel opens a read-only spreadsheet preview, including existing `/app/unknown/<uuid>` links and CSV code routes. Review **Import notes**, then choose **Edit in Macro** to create a collaborative native copy. The original file and its link remain intact. Conversion waits for a durable save before opening the copy; a failed save can be retried without creating another copy. The normal document download action retrieves the original; the spreadsheet footer exports the imported representation.+Excel (`.xlsx`, `.xlsm`) or CSV file in Files or a channel opens a read-only spreadsheet preview, including existing `/app/unknown/<uuid>` links and CSV code routes. Review **Import notes**, then choose **Edit in Macro** to create a collaborative native copy. The original file and its link remain intact. Conversion waits for a durable save before opening the copy; a failed save can be retried without creating another copy. The normal document download action retrieves the original; the spreadsheet footer exports the imported representation.You can also open a native spreadsheet and use the bottom-right **Import and export → Import…** menu to import its sheets. A large workbook shows a progress bar on **Import workbook** while it is written; the page stays responsive, and one undo removes the whole import.@@ -276,7 +276,13 @@ protection). Choose**Insert new sheets** to keep existing work, or **Replace workbook** to replace itin one undoable operation. Names must be unique when inserting sheets. Cancelingleaves the workbook untouched; a replacement is blocked if the workbook changed-while the preview was open. Legacy `.xls`, macros, and encrypted files are rejected.+while the preview was open. Encrypted files are rejected. Macro-enabled `.xlsm`+workbooks import like `.xlsx` (here and as uploads), without their macros: VBA+projects, Excel 4.0 macro sheets and form/ActiveX controls are dropped with an+import note, and **Download as Excel** writes a macro-free `.xlsx`; an uploaded+`.xlsm` keeps its macros in the original download. A legacy `.xls`+is rejected here with a hint to upload it instead; uploads convert it (see+[Legacy Office uploads](#legacy-office-uploads)).**Import and export → Download as Excel (.xlsx)** exports every sheet with formulas,current formula result caches, precise numeric values, custom Excel number formats, fonts, borders, and column widths. Named ranges, named constants, and names defined by formulas are retained and calculate. Imported legacy formulas keep Excel's implicit intersection, shown with `@` as current Excel shows it; 3-D references such as `SUM('Jan:Dec'!B2)` are listed sheet by sheet. Imported merged ranges, hidden sheets/rows/columns, row heights, filters, and frozen panes are retained for export. Macro hides imported rows and columns, shows hidden sheets and individual cells of merged ranges; editing a covered merged cell omits that merge during export with a warning so the edit is preserved. Imported charts, images, shapes, text boxes, pivot tables, conditional formatting, validation and notes are written back. Structured table formulas and rich text are not fully supported; review import notes before conversion.@@ -420,6 +426,39 @@ client. A viewer's edit must fail; a concurrent manual edit must force a freshread. These tool calls require the updated AI backend, AI editing worker, and syncservice; the frontend alone cannot test their hosted path.+## Folder uploads++Dropping a folder (or choosing one with the folder picker) zips it in the browser+and imports it as a folder tree: each subfolder becomes a folder, including empty+ones, and each file becomes a document. The folder picker cannot see empty+subfolders, so only dropped folders keep them. Office lock files (`~$…`),+`Thumbs.db`, `desktop.ini`, `__MACOSX` and hidden files or folders are skipped.+Extension case does not matter (`REPORT.DOCX` imports as `.docx`). If some files+fail, the rest of the tree still appears and a toast says some files could not be+uploaded. The unzip runs in the upload extractor Lambda, which the local stack+does not run; verify folder imports against a deployed backend.++## Legacy Office uploads++Uploaded legacy binary Office files are converted to their OpenXML equivalents+on the server: `.doc` → `.docx`, `.ppt` → `.pptx`, `.xls` → `.xlsx`. This also+applies to files inside an uploaded folder. The document keeps its id and name;+its file type changes and the converted file becomes its latest version.+Converted Word files then go through the regular DOCX pipeline, and converted+workbooks open in the uploaded-workbook preview, where **Edit in Macro** imports+them into a native spreadsheet.++While a legacy file uploaded in the last 10 minutes is converting, its view shows+**Converting … to a PowerPoint presentation…** (or Word document / Excel+workbook) with **Download** still available for the original. When the+conversion lands, the split reopens in the right block (workbooks switch in+place). If conversion fails or takes over 3 minutes, the view falls back to+**No preview available**, and the original stays downloadable. Legacy files+uploaded before conversion existed are not converted.++Conversion runs in the convert service through the upload finalizer Lambda,+neither of which the local stack runs, so verify it against a deployed backend.+## Presentations (PowerPoint)Uploaded `.pptx` files open in the `pptx` block (`/app/pptx/<documentId>`).diff --git a/infra/stacks/cloud-storage-service/document-upload-finalizer-lambda.ts b/infra/stacks/cloud-storage-service/document-upload-finalizer-lambda.tsindex 8415a4011a..7995dd692c 100644--- a/infra/stacks/cloud-storage-service/document-upload-finalizer-lambda.ts+++ b/infra/stacks/cloud-storage-service/document-upload-finalizer-lambda.ts@@ -16,11 +16,18 @@ export type DocumentUploadFinalizerLambdaEnvVars = {LEXICAL_SERVICE_URL: pulumi.Output<string> | string;SYNC_SERVICE_URL: pulumi.Output<string> | string;RUST_LOG: pulumi.Output<string> | string;+ ENVIRONMENT: pulumi.Output<string> | string;+ DOCUMENT_STORAGE_BUCKET: pulumi.Output<string> | string;+ DOCX_DOCUMENT_UPLOAD_BUCKET: pulumi.Output<string> | string;};type DocumentUploadFinalizerLambdaArgs = {envVars: DocumentUploadFinalizerLambdaEnvVars;documentStorageBucketArn: pulumi.Output<string> | string;+ /** Upgraded legacy `.doc` files are staged here for the DOCX pipeline. */+ docxUploadBucketArn: pulumi.Output<string> | string;+ /** Legacy `.doc`/`.ppt`/`.xls` uploads are upgraded through this queue. */+ convertQueueArn: pulumi.Output<string> | string;vpc: {vpcId: pulumi.Output<string> | string;publicSubnetIds: pulumi.Output<string[]> | string[];@@ -40,7 +47,14 @@ export class DocumentUploadFinalizerLambda extends pulumi.ComponentResource {opts?: pulumi.ComponentResourceOptions) {super('my:components:DocumentUploadFinalizerLambda', name, {}, opts);- const { documentStorageBucketArn, vpc, envVars, tags } = args;+ const {+ documentStorageBucketArn,+ docxUploadBucketArn,+ convertQueueArn,+ vpc,+ envVars,+ tags,+ } = args;this.tags = tags;@@ -53,9 +67,35 @@ export class DocumentUploadFinalizerLambda extends pulumi.ComponentResource {Statement: [{Effect: 'Allow',- Action: ['s3:GetObject'],+ // PutObject copies an upgraded legacy Office file into a new+ // document version.+ Action: ['s3:GetObject', 's3:PutObject'],Resource: [pulumi.interpolate`${documentStorageBucketArn}/*`],},+ {+ Effect: 'Allow',+ Action: ['s3:PutObject'],+ Resource: [pulumi.interpolate`${docxUploadBucketArn}/*`],+ },+ ],+ }),+ tags: this.tags,+ },+ { parent: this }+ );++ const sqsPolicy = new aws.iam.Policy(+ `${BASE_NAME}-sqs-policy`,+ {+ name: `${BASE_NAME}-sqs-policy-${stack}`,+ policy: pulumi.output({+ Version: '2012-10-17',+ Statement: [+ {+ Effect: 'Allow',+ Action: ['sqs:SendMessage'],+ Resource: [convertQueueArn],+ },],}),tags: this.tags,@@ -84,6 +124,7 @@ export class DocumentUploadFinalizerLambda extends pulumi.ComponentResource {aws.iam.ManagedPolicy.AWSLambdaVPCAccessExecutionRole,aws.iam.ManagedPolicy.CloudWatchLogsFullAccess,s3Policy.arn,+ sqsPolicy.arn,],tags: this.tags,},diff --git a/infra/stacks/cloud-storage-service/docx-unzip-bucket.ts b/infra/stacks/cloud-storage-service/docx-unzip-bucket.tsindex a527fb8bf8..53118f7ee9 100644--- a/infra/stacks/cloud-storage-service/docx-unzip-bucket.ts+++ b/infra/stacks/cloud-storage-service/docx-unzip-bucket.ts@@ -7,12 +7,14 @@ export function attachPolicyToDocxUnzipBucket({bulkUploadLambdaRoleArn,convertServiceRoleArn,cloudStorageServiceRoleArn,+ documentUploadFinalizerRoleArn,bucket,}: {docxUnzipLambdaRoleArn: pulumi.Output<string> | string;bulkUploadLambdaRoleArn: pulumi.Output<string> | string | undefined;convertServiceRoleArn: pulumi.Output<string> | string;cloudStorageServiceRoleArn: pulumi.Output<string> | string;+ documentUploadFinalizerRoleArn: pulumi.Output<string> | string;bucket: aws.s3.Bucket;}) {const groupName = `document-store-admin-${stack}`;@@ -34,6 +36,7 @@ export function attachPolicyToDocxUnzipBucket({docxUnzipLambdaRoleArn,cloudStorageServiceRoleArn,convertServiceRoleArn,+ documentUploadFinalizerRoleArn,];if (bulkUploadLambdaRoleArn) {arnsWithRoles.push(bulkUploadLambdaRoleArn);@@ -61,6 +64,17 @@ export function attachPolicyToDocxUnzipBucket({Resource: [bucket.arn, pulumi.interpolate`${bucket.arn}/*`],};+ // Stages upgraded legacy `.doc` files for the DOCX pipeline.+ const allowDocumentUploadFinalizerPolicyStatement: aws.iam.PolicyStatement = {+ Sid: 'AllowDocumentUploadFinalizer',+ Effect: 'Allow',+ Principal: {+ AWS: documentUploadFinalizerRoleArn,+ },+ Action: ['s3:PutObject'],+ Resource: [pulumi.interpolate`${bucket.arn}/*`],+ };+const allowDocxUnzipLambdaPolicyStatement: aws.iam.PolicyStatement = {Sid: 'AllowAccessForDocxUnzipLambda',Effect: 'Allow',@@ -98,6 +112,7 @@ export function attachPolicyToDocxUnzipBucket({allowDocumentStorageServicePolicyStatement,allowConvertServicePolicyStatement,allowDocxUnzipLambdaPolicyStatement,+ allowDocumentUploadFinalizerPolicyStatement,{Sid: 'DenyNonBucketPolicyAccessForNonAdmins',Effect: 'Deny',@@ -133,6 +148,7 @@ export function attachPolicyToDocxUnzipBucket({allowDocumentStorageServicePolicyStatement,allowConvertServicePolicyStatement,allowDocxUnzipLambdaPolicyStatement,+ allowDocumentUploadFinalizerPolicyStatement,{Sid: 'DenyNonAdminAccess',Effect: 'Deny',diff --git a/infra/stacks/cloud-storage-service/index.ts b/infra/stacks/cloud-storage-service/index.tsindex 2ae46e48bb..cb83f125ec 100644--- a/infra/stacks/cloud-storage-service/index.ts+++ b/infra/stacks/cloud-storage-service/index.ts@@ -446,12 +446,18 @@ const documentUploadFinalizerEnvVars: DocumentUploadFinalizerLambdaEnvVars = {SYNC_SERVICE_URL: getServiceUrl(ServiceUrl.SYNC_SERVICE_URL),RUST_LOG:'document_upload_finalizer_handler=info,documents=info,macro_http_request=info',+ // Selects the stack's convert queue.+ ENVIRONMENT: stack,+ DOCUMENT_STORAGE_BUCKET: pulumi.interpolate`${documentStorageBucketId}`,+ DOCX_DOCUMENT_UPLOAD_BUCKET: pulumi.interpolate`${docxUploadBucketName}`,};const documentUploadFinalizer = new DocumentUploadFinalizerLambda(`document-upload-finalizer-${stack}`,{documentStorageBucketArn,+ docxUploadBucketArn,+ convertQueueArn,envVars: documentUploadFinalizerEnvVars,vpc: coparse_api_vpc,tags,@@ -480,4 +486,5 @@ attachPolicyToDocxUnzipBucket({docxUnzipLambdaRoleArn: docxUnzipHandler.role.arn,bulkUploadLambdaRoleArn,convertServiceRoleArn,+ documentUploadFinalizerRoleArn: documentUploadFinalizer.role.arn,});diff --git a/packages/sdk/generated/cognition/types.gen.ts b/packages/sdk/generated/cognition/types.gen.tsindex b7afd33a4f..237919d416 100644--- a/packages/sdk/generated/cognition/types.gen.ts+++ b/packages/sdk/generated/cognition/types.gen.ts@@ -600,7 +600,7 @@ export type FeatureUsage = {* - ContentType::mime_type() - Gets MIME type for ContentType**/-export type FileType = 'docx' | 'pdf' | 'md' | 'spreadsheet' | 'canvas' | 'coffee' | 'cson' | 'iced' | 'c' | 'i' | 'cpp' | 'cppm' | 'cc' | 'ccm' | 'cxx' | 'cxxm' | 'cplusplus' | 'cplusplusm' | 'hpp' | 'hh' | 'hxx' | 'hplusplus' | 'h' | 'ii' | 'ino' | 'inl' | 'ipp' | 'ixx' | 'tpp' | 'txx' | 'hppin' | 'hin' | 'cu' | 'cuh' | 'cs' | 'csx' | 'cake' | 'css' | 'dart' | 'diff' | 'patch' | 'rej' | 'dockerfile' | 'containerfile' | 'go' | 'handlebars' | 'hbs' | 'hjs' | 'hlsl' | 'hlsli' | 'fx' | 'fxh' | 'vsh' | 'psh' | 'cginc' | 'compute' | 'html' | 'htm' | 'shtml' | 'xhtml' | 'xht' | 'mdoc' | 'jsp' | 'asp' | 'aspx' | 'jshtm' | 'volt' | 'ejs' | 'rhtml' | 'ini' | 'conf' | 'properties' | 'cfg' | 'directory' | 'gitattributes' | 'gitconfig' | 'gitmodules' | 'editorconfig' | 'repo' | 'java' | 'jav' | 'jsx' | 'js' | 'es6' | 'mjs' | 'cjs' | 'pac' | 'json' | 'bowerrc' | 'jscsrc' | 'webmanifest' | 'jsmap' | 'cssmap' | 'tsmap' | 'har' | 'jslintrc' | 'jsonld' | 'geojson' | 'ipynb' | 'vuerc' | 'jsonc' | 'eslintrc' | 'eslintrcjson' | 'jsfmtrc' | 'jshintrc' | 'swcrc' | 'hintrc' | 'babelrc' | 'jsonl' | 'ndjson' | 'codesnippets' | 'jl' | 'jmd' | 'sty' | 'cls' | 'bbx' | 'cbx' | 'tex' | 'ltx' | 'ctx' | 'bib' | 'less' | 'log' | 'lua' | 'mak' | 'mk' | 'mkd' | 'mdwn' | 'mdown' | 'markdown' | 'markdn' | 'mdtxt' | 'mdtext' | 'workbook' | 'm' | 'mm' | 'pl' | 'pm' | 'pod' | 't' | 'psgi' | 'raku' | 'rakumod' | 'rakutest' | 'rakudoc' | 'nqp' | 'p6' | 'pl6' | 'pm6' | 'php' | 'php4' | 'php5' | 'phtml' | 'ctp' | 'ps1' | 'psm1' | 'psd1' | 'pssc' | 'psrc' | 'py' | 'rpy' | 'pyw' | 'cpy' | 'gyp' | 'gypi' | 'pyi' | 'ipy' | 'pyt' | 'r' | 'rhistory' | 'rprofile' | 'rt' | 'cshtml' | 'razor' | 'rb' | 'rbx' | 'rjs' | 'gemspec' | 'rake' | 'ru' | 'erb' | 'podspec' | 'rbi' | 'rs' | 'scss' | 'sass' | 'shader' | 'sh' | 'bash' | 'bashrc' | 'bashaliases' | 'bashprofile' | 'bashlogin' | 'ebuild' | 'eclass' | 'profile' | 'bashlogout' | 'xprofile' | 'xsession' | 'xsessionrc' | 'zsh' | 'zshrc' | 'zprofile' | 'zlogin' | 'zlogout' | 'zshenv' | 'zshtheme' | 'fish' | 'ksh' | 'csh' | 'cshrc' | 'tcshrc' | 'yashrc' | 'yashprofile' | 'sql' | 'dsql' | 'swift' | 'ts' | 'cts' | 'mts' | 'tsx' | 'tsbuildinfo' | 'xml' | 'xsd' | 'ascx' | 'atom' | 'axml' | 'axaml' | 'bpmn' | 'cpt' | 'csl' | 'csproj' | 'csprojuser' | 'dita' | 'ditamap' | 'dtd' | 'ent' | 'mod' | 'dtml' | 'fsproj' | 'fxml' | 'iml' | 'isml' | 'jmx' | 'launch' | 'menu' | 'mxml' | 'nuspec' | 'opml' | 'owl' | 'proj' | 'props' | 'pt' | 'publishsettings' | 'pubxml' | 'pubxmluser' | 'rbxlx' | 'rbxmx' | 'rdf' | 'rng' | 'rss' | 'shproj' | 'storyboard' | 'targets' | 'tld' | 'tmx' | 'vbproj' | 'vbprojuser' | 'vcxproj' | 'vcxprojfilters' | 'wsdl' | 'wxi' | 'wxl' | 'wxs' | 'xaml' | 'xbl' | 'xib' | 'xlf' | 'xliff' | 'xpdl' | 'xul' | 'xoml' | 'xsl' | 'xslt' | 'yaml' | 'yml' | 'eyaml' | 'eyml' | 'cff' | 'yamltmlanguage' | 'yamltmpreferences' | 'yamltmtheme' | 'winget' | 'txt' | 'csv' | 'tsv' | 'jpeg' | 'jpg' | 'png' | 'gif' | 'svg' | 'webp' | 'avif' | 'bmp' | 'ico' | 'tiff' | 'tif' | 'heic' | 'heif' | 'tar' | 'targz' | 'tgz' | 'gz' | 'bz2' | 'tarbz2' | 'tbz2' | 'z' | 'tarz' | 'lz' | 'tarlz' | 'xz' | 'tarxz' | 'txz' | 'lzma' | 'tarlzma' | 'rar' | 'sevenz' | 'zst' | 'tarzst' | 'tzst' | 'zip' | 'exe' | 'msi' | 'dll' | 'bat' | 'cmd' | 'com' | 'appimage' | 'app' | 'bin' | 'deb' | 'rpm' | 'apk' | 'dmg' | 'pkg' | 'crx' | 'xpi' | 'mp3' | 'wav' | 'ogg' | 'flac' | 'aac' | 'm4a' | 'wma' | 'mid' | 'midi' | 'mp4' | 'mkv' | 'webm' | 'avi' | 'mov' | 'wmv' | 'mpg' | 'mpeg' | 'm4v' | 'flv' | 'f4v' | 'threegp' | 'ttf' | 'otf' | 'woff' | 'woff2' | 'eot' | 'rtf' | 'odt' | 'ods' | 'odp' | 'odg' | 'odf' | 'epub' | 'mobi' | 'azw' | 'azw3' | 'djvu' | 'xls' | 'ppt' | 'pptx' | 'xlsx' | 'db' | 'sqlite' | 'sqlite3' | 'mdb' | 'accdb' | 'dbf' | 'plist' | 'toml' | 'env' | 'dot' | 'gv' | 'torrent' | 'ics' | 'vcf' | 'ai' | 'eps' | 'ps' | 'dxf' | 'dwg' | 'fig' | 'psd' | 'psb' | 'stl' | 'obj' | 'fbx' | 'blend' | 'dae' | 'threeds' | 'gltf' | 'glb' | 'vhd' | 'vhdx' | 'vmdk' | 'ova' | 'ovf' | 'iso' | 'img' | 'swf';+export type FileType = 'docx' | 'pdf' | 'md' | 'spreadsheet' | 'canvas' | 'coffee' | 'cson' | 'iced' | 'c' | 'i' | 'cpp' | 'cppm' | 'cc' | 'ccm' | 'cxx' | 'cxxm' | 'cplusplus' | 'cplusplusm' | 'hpp' | 'hh' | 'hxx' | 'hplusplus' | 'h' | 'ii' | 'ino' | 'inl' | 'ipp' | 'ixx' | 'tpp' | 'txx' | 'hppin' | 'hin' | 'cu' | 'cuh' | 'cs' | 'csx' | 'cake' | 'css' | 'dart' | 'diff' | 'patch' | 'rej' | 'dockerfile' | 'containerfile' | 'go' | 'handlebars' | 'hbs' | 'hjs' | 'hlsl' | 'hlsli' | 'fx' | 'fxh' | 'vsh' | 'psh' | 'cginc' | 'compute' | 'html' | 'htm' | 'shtml' | 'xhtml' | 'xht' | 'mdoc' | 'jsp' | 'asp' | 'aspx' | 'jshtm' | 'volt' | 'ejs' | 'rhtml' | 'ini' | 'conf' | 'properties' | 'cfg' | 'directory' | 'gitattributes' | 'gitconfig' | 'gitmodules' | 'editorconfig' | 'repo' | 'java' | 'jav' | 'jsx' | 'js' | 'es6' | 'mjs' | 'cjs' | 'pac' | 'json' | 'bowerrc' | 'jscsrc' | 'webmanifest' | 'jsmap' | 'cssmap' | 'tsmap' | 'har' | 'jslintrc' | 'jsonld' | 'geojson' | 'ipynb' | 'vuerc' | 'jsonc' | 'eslintrc' | 'eslintrcjson' | 'jsfmtrc' | 'jshintrc' | 'swcrc' | 'hintrc' | 'babelrc' | 'jsonl' | 'ndjson' | 'codesnippets' | 'jl' | 'jmd' | 'sty' | 'cls' | 'bbx' | 'cbx' | 'tex' | 'ltx' | 'ctx' | 'bib' | 'less' | 'log' | 'lua' | 'mak' | 'mk' | 'mkd' | 'mdwn' | 'mdown' | 'markdown' | 'markdn' | 'mdtxt' | 'mdtext' | 'workbook' | 'm' | 'mm' | 'pl' | 'pm' | 'pod' | 't' | 'psgi' | 'raku' | 'rakumod' | 'rakutest' | 'rakudoc' | 'nqp' | 'p6' | 'pl6' | 'pm6' | 'php' | 'php4' | 'php5' | 'phtml' | 'ctp' | 'ps1' | 'psm1' | 'psd1' | 'pssc' | 'psrc' | 'py' | 'rpy' | 'pyw' | 'cpy' | 'gyp' | 'gypi' | 'pyi' | 'ipy' | 'pyt' | 'r' | 'rhistory' | 'rprofile' | 'rt' | 'cshtml' | 'razor' | 'rb' | 'rbx' | 'rjs' | 'gemspec' | 'rake' | 'ru' | 'erb' | 'podspec' | 'rbi' | 'rs' | 'scss' | 'sass' | 'shader' | 'sh' | 'bash' | 'bashrc' | 'bashaliases' | 'bashprofile' | 'bashlogin' | 'ebuild' | 'eclass' | 'profile' | 'bashlogout' | 'xprofile' | 'xsession' | 'xsessionrc' | 'zsh' | 'zshrc' | 'zprofile' | 'zlogin' | 'zlogout' | 'zshenv' | 'zshtheme' | 'fish' | 'ksh' | 'csh' | 'cshrc' | 'tcshrc' | 'yashrc' | 'yashprofile' | 'sql' | 'dsql' | 'swift' | 'ts' | 'cts' | 'mts' | 'tsx' | 'tsbuildinfo' | 'xml' | 'xsd' | 'ascx' | 'atom' | 'axml' | 'axaml' | 'bpmn' | 'cpt' | 'csl' | 'csproj' | 'csprojuser' | 'dita' | 'ditamap' | 'dtd' | 'ent' | 'mod' | 'dtml' | 'fsproj' | 'fxml' | 'iml' | 'isml' | 'jmx' | 'launch' | 'menu' | 'mxml' | 'nuspec' | 'opml' | 'owl' | 'proj' | 'props' | 'pt' | 'publishsettings' | 'pubxml' | 'pubxmluser' | 'rbxlx' | 'rbxmx' | 'rdf' | 'rng' | 'rss' | 'shproj' | 'storyboard' | 'targets' | 'tld' | 'tmx' | 'vbproj' | 'vbprojuser' | 'vcxproj' | 'vcxprojfilters' | 'wsdl' | 'wxi' | 'wxl' | 'wxs' | 'xaml' | 'xbl' | 'xib' | 'xlf' | 'xliff' | 'xpdl' | 'xul' | 'xoml' | 'xsl' | 'xslt' | 'yaml' | 'yml' | 'eyaml' | 'eyml' | 'cff' | 'yamltmlanguage' | 'yamltmpreferences' | 'yamltmtheme' | 'winget' | 'txt' | 'csv' | 'tsv' | 'jpeg' | 'jpg' | 'png' | 'gif' | 'svg' | 'webp' | 'avif' | 'bmp' | 'ico' | 'tiff' | 'tif' | 'heic' | 'heif' | 'tar' | 'targz' | 'tgz' | 'gz' | 'bz2' | 'tarbz2' | 'tbz2' | 'z' | 'tarz' | 'lz' | 'tarlz' | 'xz' | 'tarxz' | 'txz' | 'lzma' | 'tarlzma' | 'rar' | 'sevenz' | 'zst' | 'tarzst' | 'tzst' | 'zip' | 'exe' | 'msi' | 'dll' | 'bat' | 'cmd' | 'com' | 'appimage' | 'app' | 'bin' | 'deb' | 'rpm' | 'apk' | 'dmg' | 'pkg' | 'crx' | 'xpi' | 'mp3' | 'wav' | 'ogg' | 'flac' | 'aac' | 'm4a' | 'wma' | 'mid' | 'midi' | 'mp4' | 'mkv' | 'webm' | 'avi' | 'mov' | 'wmv' | 'mpg' | 'mpeg' | 'm4v' | 'flv' | 'f4v' | 'threegp' | 'ttf' | 'otf' | 'woff' | 'woff2' | 'eot' | 'rtf' | 'odt' | 'ods' | 'odp' | 'odg' | 'odf' | 'epub' | 'mobi' | 'azw' | 'azw3' | 'djvu' | 'xls' | 'xlsm' | 'ppt' | 'doc' | 'pptx' | 'xlsx' | 'db' | 'sqlite' | 'sqlite3' | 'mdb' | 'accdb' | 'dbf' | 'plist' | 'toml' | 'env' | 'dot' | 'gv' | 'torrent' | 'ics' | 'vcf' | 'ai' | 'eps' | 'ps' | 'dxf' | 'dwg' | 'fig' | 'psd' | 'psb' | 'stl' | 'obj' | 'fbx' | 'blend' | 'dae' | 'threeds' | 'gltf' | 'glb' | 'vhd' | 'vhdx' | 'vmdk' | 'ova' | 'ovf' | 'iso' | 'img' | 'swf';export type GenericErrorResponse = {/**diff --git a/packages/sdk/generated/search/types.gen.ts b/packages/sdk/generated/search/types.gen.tsindex c08f4633d5..2e57a301db 100644--- a/packages/sdk/generated/search/types.gen.ts+++ b/packages/sdk/generated/search/types.gen.ts@@ -1398,7 +1398,7 @@ export type ErrorResponse = {* - ContentType::mime_type() - Gets MIME type for ContentType**/-export type FileType = 'docx' | 'pdf' | 'md' | 'spreadsheet' | 'canvas' | 'coffee' | 'cson' | 'iced' | 'c' | 'i' | 'cpp' | 'cppm' | 'cc' | 'ccm' | 'cxx' | 'cxxm' | 'cplusplus' | 'cplusplusm' | 'hpp' | 'hh' | 'hxx' | 'hplusplus' | 'h' | 'ii' | 'ino' | 'inl' | 'ipp' | 'ixx' | 'tpp' | 'txx' | 'hppin' | 'hin' | 'cu' | 'cuh' | 'cs' | 'csx' | 'cake' | 'css' | 'dart' | 'diff' | 'patch' | 'rej' | 'dockerfile' | 'containerfile' | 'go' | 'handlebars' | 'hbs' | 'hjs' | 'hlsl' | 'hlsli' | 'fx' | 'fxh' | 'vsh' | 'psh' | 'cginc' | 'compute' | 'html' | 'htm' | 'shtml' | 'xhtml' | 'xht' | 'mdoc' | 'jsp' | 'asp' | 'aspx' | 'jshtm' | 'volt' | 'ejs' | 'rhtml' | 'ini' | 'conf' | 'properties' | 'cfg' | 'directory' | 'gitattributes' | 'gitconfig' | 'gitmodules' | 'editorconfig' | 'repo' | 'java' | 'jav' | 'jsx' | 'js' | 'es6' | 'mjs' | 'cjs' | 'pac' | 'json' | 'bowerrc' | 'jscsrc' | 'webmanifest' | 'jsmap' | 'cssmap' | 'tsmap' | 'har' | 'jslintrc' | 'jsonld' | 'geojson' | 'ipynb' | 'vuerc' | 'jsonc' | 'eslintrc' | 'eslintrcjson' | 'jsfmtrc' | 'jshintrc' | 'swcrc' | 'hintrc' | 'babelrc' | 'jsonl' | 'ndjson' | 'codesnippets' | 'jl' | 'jmd' | 'sty' | 'cls' | 'bbx' | 'cbx' | 'tex' | 'ltx' | 'ctx' | 'bib' | 'less' | 'log' | 'lua' | 'mak' | 'mk' | 'mkd' | 'mdwn' | 'mdown' | 'markdown' | 'markdn' | 'mdtxt' | 'mdtext' | 'workbook' | 'm' | 'mm' | 'pl' | 'pm' | 'pod' | 't' | 'psgi' | 'raku' | 'rakumod' | 'rakutest' | 'rakudoc' | 'nqp' | 'p6' | 'pl6' | 'pm6' | 'php' | 'php4' | 'php5' | 'phtml' | 'ctp' | 'ps1' | 'psm1' | 'psd1' | 'pssc' | 'psrc' | 'py' | 'rpy' | 'pyw' | 'cpy' | 'gyp' | 'gypi' | 'pyi' | 'ipy' | 'pyt' | 'r' | 'rhistory' | 'rprofile' | 'rt' | 'cshtml' | 'razor' | 'rb' | 'rbx' | 'rjs' | 'gemspec' | 'rake' | 'ru' | 'erb' | 'podspec' | 'rbi' | 'rs' | 'scss' | 'sass' | 'shader' | 'sh' | 'bash' | 'bashrc' | 'bashaliases' | 'bashprofile' | 'bashlogin' | 'ebuild' | 'eclass' | 'profile' | 'bashlogout' | 'xprofile' | 'xsession' | 'xsessionrc' | 'zsh' | 'zshrc' | 'zprofile' | 'zlogin' | 'zlogout' | 'zshenv' | 'zshtheme' | 'fish' | 'ksh' | 'csh' | 'cshrc' | 'tcshrc' | 'yashrc' | 'yashprofile' | 'sql' | 'dsql' | 'swift' | 'ts' | 'cts' | 'mts' | 'tsx' | 'tsbuildinfo' | 'xml' | 'xsd' | 'ascx' | 'atom' | 'axml' | 'axaml' | 'bpmn' | 'cpt' | 'csl' | 'csproj' | 'csprojuser' | 'dita' | 'ditamap' | 'dtd' | 'ent' | 'mod' | 'dtml' | 'fsproj' | 'fxml' | 'iml' | 'isml' | 'jmx' | 'launch' | 'menu' | 'mxml' | 'nuspec' | 'opml' | 'owl' | 'proj' | 'props' | 'pt' | 'publishsettings' | 'pubxml' | 'pubxmluser' | 'rbxlx' | 'rbxmx' | 'rdf' | 'rng' | 'rss' | 'shproj' | 'storyboard' | 'targets' | 'tld' | 'tmx' | 'vbproj' | 'vbprojuser' | 'vcxproj' | 'vcxprojfilters' | 'wsdl' | 'wxi' | 'wxl' | 'wxs' | 'xaml' | 'xbl' | 'xib' | 'xlf' | 'xliff' | 'xpdl' | 'xul' | 'xoml' | 'xsl' | 'xslt' | 'yaml' | 'yml' | 'eyaml' | 'eyml' | 'cff' | 'yamltmlanguage' | 'yamltmpreferences' | 'yamltmtheme' | 'winget' | 'txt' | 'csv' | 'tsv' | 'jpeg' | 'jpg' | 'png' | 'gif' | 'svg' | 'webp' | 'avif' | 'bmp' | 'ico' | 'tiff' | 'tif' | 'heic' | 'heif' | 'tar' | 'targz' | 'tgz' | 'gz' | 'bz2' | 'tarbz2' | 'tbz2' | 'z' | 'tarz' | 'lz' | 'tarlz' | 'xz' | 'tarxz' | 'txz' | 'lzma' | 'tarlzma' | 'rar' | 'sevenz' | 'zst' | 'tarzst' | 'tzst' | 'zip' | 'exe' | 'msi' | 'dll' | 'bat' | 'cmd' | 'com' | 'appimage' | 'app' | 'bin' | 'deb' | 'rpm' | 'apk' | 'dmg' | 'pkg' | 'crx' | 'xpi' | 'mp3' | 'wav' | 'ogg' | 'flac' | 'aac' | 'm4a' | 'wma' | 'mid' | 'midi' | 'mp4' | 'mkv' | 'webm' | 'avi' | 'mov' | 'wmv' | 'mpg' | 'mpeg' | 'm4v' | 'flv' | 'f4v' | 'threegp' | 'ttf' | 'otf' | 'woff' | 'woff2' | 'eot' | 'rtf' | 'odt' | 'ods' | 'odp' | 'odg' | 'odf' | 'epub' | 'mobi' | 'azw' | 'azw3' | 'djvu' | 'xls' | 'ppt' | 'pptx' | 'xlsx' | 'db' | 'sqlite' | 'sqlite3' | 'mdb' | 'accdb' | 'dbf' | 'plist' | 'toml' | 'env' | 'dot' | 'gv' | 'torrent' | 'ics' | 'vcf' | 'ai' | 'eps' | 'ps' | 'dxf' | 'dwg' | 'fig' | 'psd' | 'psb' | 'stl' | 'obj' | 'fbx' | 'blend' | 'dae' | 'threeds' | 'gltf' | 'glb' | 'vhd' | 'vhdx' | 'vmdk' | 'ova' | 'ovf' | 'iso' | 'img' | 'swf';+export type FileType = 'docx' | 'pdf' | 'md' | 'spreadsheet' | 'canvas' | 'coffee' | 'cson' | 'iced' | 'c' | 'i' | 'cpp' | 'cppm' | 'cc' | 'ccm' | 'cxx' | 'cxxm' | 'cplusplus' | 'cplusplusm' | 'hpp' | 'hh' | 'hxx' | 'hplusplus' | 'h' | 'ii' | 'ino' | 'inl' | 'ipp' | 'ixx' | 'tpp' | 'txx' | 'hppin' | 'hin' | 'cu' | 'cuh' | 'cs' | 'csx' | 'cake' | 'css' | 'dart' | 'diff' | 'patch' | 'rej' | 'dockerfile' | 'containerfile' | 'go' | 'handlebars' | 'hbs' | 'hjs' | 'hlsl' | 'hlsli' | 'fx' | 'fxh' | 'vsh' | 'psh' | 'cginc' | 'compute' | 'html' | 'htm' | 'shtml' | 'xhtml' | 'xht' | 'mdoc' | 'jsp' | 'asp' | 'aspx' | 'jshtm' | 'volt' | 'ejs' | 'rhtml' | 'ini' | 'conf' | 'properties' | 'cfg' | 'directory' | 'gitattributes' | 'gitconfig' | 'gitmodules' | 'editorconfig' | 'repo' | 'java' | 'jav' | 'jsx' | 'js' | 'es6' | 'mjs' | 'cjs' | 'pac' | 'json' | 'bowerrc' | 'jscsrc' | 'webmanifest' | 'jsmap' | 'cssmap' | 'tsmap' | 'har' | 'jslintrc' | 'jsonld' | 'geojson' | 'ipynb' | 'vuerc' | 'jsonc' | 'eslintrc' | 'eslintrcjson' | 'jsfmtrc' | 'jshintrc' | 'swcrc' | 'hintrc' | 'babelrc' | 'jsonl' | 'ndjson' | 'codesnippets' | 'jl' | 'jmd' | 'sty' | 'cls' | 'bbx' | 'cbx' | 'tex' | 'ltx' | 'ctx' | 'bib' | 'less' | 'log' | 'lua' | 'mak' | 'mk' | 'mkd' | 'mdwn' | 'mdown' | 'markdown' | 'markdn' | 'mdtxt' | 'mdtext' | 'workbook' | 'm' | 'mm' | 'pl' | 'pm' | 'pod' | 't' | 'psgi' | 'raku' | 'rakumod' | 'rakutest' | 'rakudoc' | 'nqp' | 'p6' | 'pl6' | 'pm6' | 'php' | 'php4' | 'php5' | 'phtml' | 'ctp' | 'ps1' | 'psm1' | 'psd1' | 'pssc' | 'psrc' | 'py' | 'rpy' | 'pyw' | 'cpy' | 'gyp' | 'gypi' | 'pyi' | 'ipy' | 'pyt' | 'r' | 'rhistory' | 'rprofile' | 'rt' | 'cshtml' | 'razor' | 'rb' | 'rbx' | 'rjs' | 'gemspec' | 'rake' | 'ru' | 'erb' | 'podspec' | 'rbi' | 'rs' | 'scss' | 'sass' | 'shader' | 'sh' | 'bash' | 'bashrc' | 'bashaliases' | 'bashprofile' | 'bashlogin' | 'ebuild' | 'eclass' | 'profile' | 'bashlogout' | 'xprofile' | 'xsession' | 'xsessionrc' | 'zsh' | 'zshrc' | 'zprofile' | 'zlogin' | 'zlogout' | 'zshenv' | 'zshtheme' | 'fish' | 'ksh' | 'csh' | 'cshrc' | 'tcshrc' | 'yashrc' | 'yashprofile' | 'sql' | 'dsql' | 'swift' | 'ts' | 'cts' | 'mts' | 'tsx' | 'tsbuildinfo' | 'xml' | 'xsd' | 'ascx' | 'atom' | 'axml' | 'axaml' | 'bpmn' | 'cpt' | 'csl' | 'csproj' | 'csprojuser' | 'dita' | 'ditamap' | 'dtd' | 'ent' | 'mod' | 'dtml' | 'fsproj' | 'fxml' | 'iml' | 'isml' | 'jmx' | 'launch' | 'menu' | 'mxml' | 'nuspec' | 'opml' | 'owl' | 'proj' | 'props' | 'pt' | 'publishsettings' | 'pubxml' | 'pubxmluser' | 'rbxlx' | 'rbxmx' | 'rdf' | 'rng' | 'rss' | 'shproj' | 'storyboard' | 'targets' | 'tld' | 'tmx' | 'vbproj' | 'vbprojuser' | 'vcxproj' | 'vcxprojfilters' | 'wsdl' | 'wxi' | 'wxl' | 'wxs' | 'xaml' | 'xbl' | 'xib' | 'xlf' | 'xliff' | 'xpdl' | 'xul' | 'xoml' | 'xsl' | 'xslt' | 'yaml' | 'yml' | 'eyaml' | 'eyml' | 'cff' | 'yamltmlanguage' | 'yamltmpreferences' | 'yamltmtheme' | 'winget' | 'txt' | 'csv' | 'tsv' | 'jpeg' | 'jpg' | 'png' | 'gif' | 'svg' | 'webp' | 'avif' | 'bmp' | 'ico' | 'tiff' | 'tif' | 'heic' | 'heif' | 'tar' | 'targz' | 'tgz' | 'gz' | 'bz2' | 'tarbz2' | 'tbz2' | 'z' | 'tarz' | 'lz' | 'tarlz' | 'xz' | 'tarxz' | 'txz' | 'lzma' | 'tarlzma' | 'rar' | 'sevenz' | 'zst' | 'tarzst' | 'tzst' | 'zip' | 'exe' | 'msi' | 'dll' | 'bat' | 'cmd' | 'com' | 'appimage' | 'app' | 'bin' | 'deb' | 'rpm' | 'apk' | 'dmg' | 'pkg' | 'crx' | 'xpi' | 'mp3' | 'wav' | 'ogg' | 'flac' | 'aac' | 'm4a' | 'wma' | 'mid' | 'midi' | 'mp4' | 'mkv' | 'webm' | 'avi' | 'mov' | 'wmv' | 'mpg' | 'mpeg' | 'm4v' | 'flv' | 'f4v' | 'threegp' | 'ttf' | 'otf' | 'woff' | 'woff2' | 'eot' | 'rtf' | 'odt' | 'ods' | 'odp' | 'odg' | 'odf' | 'epub' | 'mobi' | 'azw' | 'azw3' | 'djvu' | 'xls' | 'xlsm' | 'ppt' | 'doc' | 'pptx' | 'xlsx' | 'db' | 'sqlite' | 'sqlite3' | 'mdb' | 'accdb' | 'dbf' | 'plist' | 'toml' | 'env' | 'dot' | 'gv' | 'torrent' | 'ics' | 'vcf' | 'ai' | 'eps' | 'ps' | 'dxf' | 'dwg' | 'fig' | 'psd' | 'psb' | 'stl' | 'obj' | 'fbx' | 'blend' | 'dae' | 'threeds' | 'gltf' | 'glb' | 'vhd' | 'vhdx' | 'vmdk' | 'ova' | 'ovf' | 'iso' | 'img' | 'swf';/*** Filters for foreign entity records.diff --git a/packages/sdk/generated/storage/types.gen.ts b/packages/sdk/generated/storage/types.gen.tsindex dd9663685e..097f7f66ef 100644--- a/packages/sdk/generated/storage/types.gen.ts+++ b/packages/sdk/generated/storage/types.gen.ts@@ -6054,7 +6054,7 @@ export type FileSystemNodeWithIds = {* - ContentType::mime_type() - Gets MIME type for ContentType**/-export type FileType = 'docx' | 'pdf' | 'md' | 'spreadsheet' | 'canvas' | 'coffee' | 'cson' | 'iced' | 'c' | 'i' | 'cpp' | 'cppm' | 'cc' | 'ccm' | 'cxx' | 'cxxm' | 'cplusplus' | 'cplusplusm' | 'hpp' | 'hh' | 'hxx' | 'hplusplus' | 'h' | 'ii' | 'ino' | 'inl' | 'ipp' | 'ixx' | 'tpp' | 'txx' | 'hppin' | 'hin' | 'cu' | 'cuh' | 'cs' | 'csx' | 'cake' | 'css' | 'dart' | 'diff' | 'patch' | 'rej' | 'dockerfile' | 'containerfile' | 'go' | 'handlebars' | 'hbs' | 'hjs' | 'hlsl' | 'hlsli' | 'fx' | 'fxh' | 'vsh' | 'psh' | 'cginc' | 'compute' | 'html' | 'htm' | 'shtml' | 'xhtml' | 'xht' | 'mdoc' | 'jsp' | 'asp' | 'aspx' | 'jshtm' | 'volt' | 'ejs' | 'rhtml' | 'ini' | 'conf' | 'properties' | 'cfg' | 'directory' | 'gitattributes' | 'gitconfig' | 'gitmodules' | 'editorconfig' | 'repo' | 'java' | 'jav' | 'jsx' | 'js' | 'es6' | 'mjs' | 'cjs' | 'pac' | 'json' | 'bowerrc' | 'jscsrc' | 'webmanifest' | 'jsmap' | 'cssmap' | 'tsmap' | 'har' | 'jslintrc' | 'jsonld' | 'geojson' | 'ipynb' | 'vuerc' | 'jsonc' | 'eslintrc' | 'eslintrcjson' | 'jsfmtrc' | 'jshintrc' | 'swcrc' | 'hintrc' | 'babelrc' | 'jsonl' | 'ndjson' | 'codesnippets' | 'jl' | 'jmd' | 'sty' | 'cls' | 'bbx' | 'cbx' | 'tex' | 'ltx' | 'ctx' | 'bib' | 'less' | 'log' | 'lua' | 'mak' | 'mk' | 'mkd' | 'mdwn' | 'mdown' | 'markdown' | 'markdn' | 'mdtxt' | 'mdtext' | 'workbook' | 'm' | 'mm' | 'pl' | 'pm' | 'pod' | 't' | 'psgi' | 'raku' | 'rakumod' | 'rakutest' | 'rakudoc' | 'nqp' | 'p6' | 'pl6' | 'pm6' | 'php' | 'php4' | 'php5' | 'phtml' | 'ctp' | 'ps1' | 'psm1' | 'psd1' | 'pssc' | 'psrc' | 'py' | 'rpy' | 'pyw' | 'cpy' | 'gyp' | 'gypi' | 'pyi' | 'ipy' | 'pyt' | 'r' | 'rhistory' | 'rprofile' | 'rt' | 'cshtml' | 'razor' | 'rb' | 'rbx' | 'rjs' | 'gemspec' | 'rake' | 'ru' | 'erb' | 'podspec' | 'rbi' | 'rs' | 'scss' | 'sass' | 'shader' | 'sh' | 'bash' | 'bashrc' | 'bashaliases' | 'bashprofile' | 'bashlogin' | 'ebuild' | 'eclass' | 'profile' | 'bashlogout' | 'xprofile' | 'xsession' | 'xsessionrc' | 'zsh' | 'zshrc' | 'zprofile' | 'zlogin' | 'zlogout' | 'zshenv' | 'zshtheme' | 'fish' | 'ksh' | 'csh' | 'cshrc' | 'tcshrc' | 'yashrc' | 'yashprofile' | 'sql' | 'dsql' | 'swift' | 'ts' | 'cts' | 'mts' | 'tsx' | 'tsbuildinfo' | 'xml' | 'xsd' | 'ascx' | 'atom' | 'axml' | 'axaml' | 'bpmn' | 'cpt' | 'csl' | 'csproj' | 'csprojuser' | 'dita' | 'ditamap' | 'dtd' | 'ent' | 'mod' | 'dtml' | 'fsproj' | 'fxml' | 'iml' | 'isml' | 'jmx' | 'launch' | 'menu' | 'mxml' | 'nuspec' | 'opml' | 'owl' | 'proj' | 'props' | 'pt' | 'publishsettings' | 'pubxml' | 'pubxmluser' | 'rbxlx' | 'rbxmx' | 'rdf' | 'rng' | 'rss' | 'shproj' | 'storyboard' | 'targets' | 'tld' | 'tmx' | 'vbproj' | 'vbprojuser' | 'vcxproj' | 'vcxprojfilters' | 'wsdl' | 'wxi' | 'wxl' | 'wxs' | 'xaml' | 'xbl' | 'xib' | 'xlf' | 'xliff' | 'xpdl' | 'xul' | 'xoml' | 'xsl' | 'xslt' | 'yaml' | 'yml' | 'eyaml' | 'eyml' | 'cff' | 'yamltmlanguage' | 'yamltmpreferences' | 'yamltmtheme' | 'winget' | 'txt' | 'csv' | 'tsv' | 'jpeg' | 'jpg' | 'png' | 'gif' | 'svg' | 'webp' | 'avif' | 'bmp' | 'ico' | 'tiff' | 'tif' | 'heic' | 'heif' | 'tar' | 'targz' | 'tgz' | 'gz' | 'bz2' | 'tarbz2' | 'tbz2' | 'z' | 'tarz' | 'lz' | 'tarlz' | 'xz' | 'tarxz' | 'txz' | 'lzma' | 'tarlzma' | 'rar' | 'sevenz' | 'zst' | 'tarzst' | 'tzst' | 'zip' | 'exe' | 'msi' | 'dll' | 'bat' | 'cmd' | 'com' | 'appimage' | 'app' | 'bin' | 'deb' | 'rpm' | 'apk' | 'dmg' | 'pkg' | 'crx' | 'xpi' | 'mp3' | 'wav' | 'ogg' | 'flac' | 'aac' | 'm4a' | 'wma' | 'mid' | 'midi' | 'mp4' | 'mkv' | 'webm' | 'avi' | 'mov' | 'wmv' | 'mpg' | 'mpeg' | 'm4v' | 'flv' | 'f4v' | 'threegp' | 'ttf' | 'otf' | 'woff' | 'woff2' | 'eot' | 'rtf' | 'odt' | 'ods' | 'odp' | 'odg' | 'odf' | 'epub' | 'mobi' | 'azw' | 'azw3' | 'djvu' | 'xls' | 'ppt' | 'pptx' | 'xlsx' | 'db' | 'sqlite' | 'sqlite3' | 'mdb' | 'accdb' | 'dbf' | 'plist' | 'toml' | 'env' | 'dot' | 'gv' | 'torrent' | 'ics' | 'vcf' | 'ai' | 'eps' | 'ps' | 'dxf' | 'dwg' | 'fig' | 'psd' | 'psb' | 'stl' | 'obj' | 'fbx' | 'blend' | 'dae' | 'threeds' | 'gltf' | 'glb' | 'vhd' | 'vhdx' | 'vmdk' | 'ova' | 'ovf' | 'iso' | 'img' | 'swf';+export type FileType = 'docx' | 'pdf' | 'md' | 'spreadsheet' | 'canvas' | 'coffee' | 'cson' | 'iced' | 'c' | 'i' | 'cpp' | 'cppm' | 'cc' | 'ccm' | 'cxx' | 'cxxm' | 'cplusplus' | 'cplusplusm' | 'hpp' | 'hh' | 'hxx' | 'hplusplus' | 'h' | 'ii' | 'ino' | 'inl' | 'ipp' | 'ixx' | 'tpp' | 'txx' | 'hppin' | 'hin' | 'cu' | 'cuh' | 'cs' | 'csx' | 'cake' | 'css' | 'dart' | 'diff' | 'patch' | 'rej' | 'dockerfile' | 'containerfile' | 'go' | 'handlebars' | 'hbs' | 'hjs' | 'hlsl' | 'hlsli' | 'fx' | 'fxh' | 'vsh' | 'psh' | 'cginc' | 'compute' | 'html' | 'htm' | 'shtml' | 'xhtml' | 'xht' | 'mdoc' | 'jsp' | 'asp' | 'aspx' | 'jshtm' | 'volt' | 'ejs' | 'rhtml' | 'ini' | 'conf' | 'properties' | 'cfg' | 'directory' | 'gitattributes' | 'gitconfig' | 'gitmodules' | 'editorconfig' | 'repo' | 'java' | 'jav' | 'jsx' | 'js' | 'es6' | 'mjs' | 'cjs' | 'pac' | 'json' | 'bowerrc' | 'jscsrc' | 'webmanifest' | 'jsmap' | 'cssmap' | 'tsmap' | 'har' | 'jslintrc' | 'jsonld' | 'geojson' | 'ipynb' | 'vuerc' | 'jsonc' | 'eslintrc' | 'eslintrcjson' | 'jsfmtrc' | 'jshintrc' | 'swcrc' | 'hintrc' | 'babelrc' | 'jsonl' | 'ndjson' | 'codesnippets' | 'jl' | 'jmd' | 'sty' | 'cls' | 'bbx' | 'cbx' | 'tex' | 'ltx' | 'ctx' | 'bib' | 'less' | 'log' | 'lua' | 'mak' | 'mk' | 'mkd' | 'mdwn' | 'mdown' | 'markdown' | 'markdn' | 'mdtxt' | 'mdtext' | 'workbook' | 'm' | 'mm' | 'pl' | 'pm' | 'pod' | 't' | 'psgi' | 'raku' | 'rakumod' | 'rakutest' | 'rakudoc' | 'nqp' | 'p6' | 'pl6' | 'pm6' | 'php' | 'php4' | 'php5' | 'phtml' | 'ctp' | 'ps1' | 'psm1' | 'psd1' | 'pssc' | 'psrc' | 'py' | 'rpy' | 'pyw' | 'cpy' | 'gyp' | 'gypi' | 'pyi' | 'ipy' | 'pyt' | 'r' | 'rhistory' | 'rprofile' | 'rt' | 'cshtml' | 'razor' | 'rb' | 'rbx' | 'rjs' | 'gemspec' | 'rake' | 'ru' | 'erb' | 'podspec' | 'rbi' | 'rs' | 'scss' | 'sass' | 'shader' | 'sh' | 'bash' | 'bashrc' | 'bashaliases' | 'bashprofile' | 'bashlogin' | 'ebuild' | 'eclass' | 'profile' | 'bashlogout' | 'xprofile' | 'xsession' | 'xsessionrc' | 'zsh' | 'zshrc' | 'zprofile' | 'zlogin' | 'zlogout' | 'zshenv' | 'zshtheme' | 'fish' | 'ksh' | 'csh' | 'cshrc' | 'tcshrc' | 'yashrc' | 'yashprofile' | 'sql' | 'dsql' | 'swift' | 'ts' | 'cts' | 'mts' | 'tsx' | 'tsbuildinfo' | 'xml' | 'xsd' | 'ascx' | 'atom' | 'axml' | 'axaml' | 'bpmn' | 'cpt' | 'csl' | 'csproj' | 'csprojuser' | 'dita' | 'ditamap' | 'dtd' | 'ent' | 'mod' | 'dtml' | 'fsproj' | 'fxml' | 'iml' | 'isml' | 'jmx' | 'launch' | 'menu' | 'mxml' | 'nuspec' | 'opml' | 'owl' | 'proj' | 'props' | 'pt' | 'publishsettings' | 'pubxml' | 'pubxmluser' | 'rbxlx' | 'rbxmx' | 'rdf' | 'rng' | 'rss' | 'shproj' | 'storyboard' | 'targets' | 'tld' | 'tmx' | 'vbproj' | 'vbprojuser' | 'vcxproj' | 'vcxprojfilters' | 'wsdl' | 'wxi' | 'wxl' | 'wxs' | 'xaml' | 'xbl' | 'xib' | 'xlf' | 'xliff' | 'xpdl' | 'xul' | 'xoml' | 'xsl' | 'xslt' | 'yaml' | 'yml' | 'eyaml' | 'eyml' | 'cff' | 'yamltmlanguage' | 'yamltmpreferences' | 'yamltmtheme' | 'winget' | 'txt' | 'csv' | 'tsv' | 'jpeg' | 'jpg' | 'png' | 'gif' | 'svg' | 'webp' | 'avif' | 'bmp' | 'ico' | 'tiff' | 'tif' | 'heic' | 'heif' | 'tar' | 'targz' | 'tgz' | 'gz' | 'bz2' | 'tarbz2' | 'tbz2' | 'z' | 'tarz' | 'lz' | 'tarlz' | 'xz' | 'tarxz' | 'txz' | 'lzma' | 'tarlzma' | 'rar' | 'sevenz' | 'zst' | 'tarzst' | 'tzst' | 'zip' | 'exe' | 'msi' | 'dll' | 'bat' | 'cmd' | 'com' | 'appimage' | 'app' | 'bin' | 'deb' | 'rpm' | 'apk' | 'dmg' | 'pkg' | 'crx' | 'xpi' | 'mp3' | 'wav' | 'ogg' | 'flac' | 'aac' | 'm4a' | 'wma' | 'mid' | 'midi' | 'mp4' | 'mkv' | 'webm' | 'avi' | 'mov' | 'wmv' | 'mpg' | 'mpeg' | 'm4v' | 'flv' | 'f4v' | 'threegp' | 'ttf' | 'otf' | 'woff' | 'woff2' | 'eot' | 'rtf' | 'odt' | 'ods' | 'odp' | 'odg' | 'odf' | 'epub' | 'mobi' | 'azw' | 'azw3' | 'djvu' | 'xls' | 'xlsm' | 'ppt' | 'doc' | 'pptx' | 'xlsx' | 'db' | 'sqlite' | 'sqlite3' | 'mdb' | 'accdb' | 'dbf' | 'plist' | 'toml' | 'env' | 'dot' | 'gv' | 'torrent' | 'ics' | 'vcf' | 'ai' | 'eps' | 'ps' | 'dxf' | 'dwg' | 'fig' | 'psd' | 'psb' | 'stl' | 'obj' | 'fbx' | 'blend' | 'dae' | 'threeds' | 'gltf' | 'glb' | 'vhd' | 'vhdx' | 'vmdk' | 'ova' | 'ovf' | 'iso' | 'img' | 'swf';/*** Represents a file type update: either set to a specific type or clear to null.@@ -12755,6 +12755,12 @@ export type UploadFolderRequest = {* The content of the folder*/content: Array<FolderItem>;+ /**+ * Relative paths of folders to create even when they hold no files.+ *+ * Uses the same shape as [FolderItem::relative_path], root folder included.+ */+ folders?: Array<string>;/*** Optional parent project id to upload the folder into*/diff --git a/packages/sdk/specs/cognition.json b/packages/sdk/specs/cognition.jsonindex 60c809ff1f..a409791479 100644--- a/packages/sdk/specs/cognition.json+++ b/packages/sdk/specs/cognition.json@@ -3600,7 +3600,9 @@"azw3","djvu","xls",+ "xlsm","ppt",+ "doc","pptx","xlsx","db",diff --git a/packages/sdk/specs/search.json b/packages/sdk/specs/search.jsonindex 587ec52d4b..742ad60759 100644--- a/packages/sdk/specs/search.json+++ b/packages/sdk/specs/search.json@@ -2636,7 +2636,9 @@"azw3","djvu","xls",+ "xlsm","ppt",+ "doc","pptx","xlsx","db",diff --git a/packages/sdk/specs/storage.json b/packages/sdk/specs/storage.jsonindex 5b23562460..7e0ef8fbce 100644--- a/packages/sdk/specs/storage.json+++ b/packages/sdk/specs/storage.json@@ -25169,7 +25169,9 @@"azw3","djvu","xls",+ "xlsm","ppt",+ "doc","pptx","xlsx","db",@@ -35822,6 +35824,13 @@},"description": "The content of the folder"},+ "folders": {+ "type": "array",+ "items": {+ "type": "string"+ },+ "description": "Relative paths of folders to create even when they hold no files.\n\nUses the same shape as [FolderItem::relative_path], root folder included."+ },"parentId": {"type": ["string", "null"],"description": "Optional parent project id to upload the folder into"diff --git a/services/convert_service/Cargo.toml b/services/convert_service/Cargo.tomlindex 3b0326ce00..0b2bfe6c3c 100644--- a/services/convert_service/Cargo.toml+++ b/services/convert_service/Cargo.toml@@ -60,3 +60,8 @@ utoipa = { workspace = true }utoipa-swagger-ui = { workspace = true }zip = { workspace = true, features = ["bzip2"] }workspace-hack = { version = "0.1", path = "../../crates/workspace-hack" }++[dev-dependencies]+docx_engine = { path = "../../crates/docx_engine" }+pptx_engine = { path = "../../crates/pptx_engine" }+tempfile = { workspace = true }diff --git a/services/convert_service/fixtures/legacy/budget.xls b/services/convert_service/fixtures/legacy/budget.xlsnew file mode 100644index 0000000000..bcffd9adceBinary files /dev/null and b/services/convert_service/fixtures/legacy/budget.xls differdiff --git a/services/convert_service/fixtures/legacy/deck.ppt b/services/convert_service/fixtures/legacy/deck.pptnew file mode 100644index 0000000000..52f92abfacBinary files /dev/null and b/services/convert_service/fixtures/legacy/deck.ppt differdiff --git a/services/convert_service/fixtures/legacy/memo.doc b/services/convert_service/fixtures/legacy/memo.docnew file mode 100644index 0000000000..1fed2d03f2Binary files /dev/null and b/services/convert_service/fixtures/legacy/memo.doc differdiff --git a/services/convert_service/src/api/backfill/backfill_docx.rs b/services/convert_service/src/api/backfill/backfill_docx.rsindex 16d33108b4..facdd0c804 100644--- a/services/convert_service/src/api/backfill/backfill_docx.rs+++ b/services/convert_service/src/api/backfill/backfill_docx.rs@@ -182,6 +182,8 @@ async fn process_docx(to_bucket: document_storage_bucket.to_string(),from_key: from_key.clone(),to_key: to_key.clone(),+ from_file_type: None,+ to_file_type: None,}));}diff --git a/services/convert_service/src/process/convert.rs b/services/convert_service/src/process/convert.rsindex 74eb7b7a18..67e4a75f32 100644--- a/services/convert_service/src/process/convert.rs+++ b/services/convert_service/src/process/convert.rs@@ -1,21 +1,21 @@use nix::{- libc::exit,+ libc::{_exit, exit},unistd::{ForkResult, fork},};use rs_libreoffice_bindings::Office;-use std::{borrow::Cow, fs::File, io::Write, str::FromStr, thread, time::Duration};+use std::{borrow::Cow, fs::File, io::Write, thread, time::Duration};use anyhow::Context;-use model::{convert::ConvertQueueMessage, document::FileType};+use model::convert::ConvertQueueMessage;use crate::{config::{LOK_PATH, WEB_SOCKET_RESPONSE_LAMBDA},model::{BomPart, DocxUploadJobData, DocxUploadJobResult, DocxUploadJobSuccessDataInner},- utils::{cleanup_folder, get_lok_filter_from_file_types},+ utils::{+ cleanup_folder, conversion_timeout, get_lok_filter_from_file_types, resolve_file_type,+ },};-static MAX_WAIT_TIME_SECONDS: u64 = 30;-pub(super) fn is_docx_key(key: &str) -> bool {key.to_ascii_lowercase().ends_with(".docx")}@@ -135,19 +135,8 @@ pub async fn convert(req: &ConvertQueueMessage,s3_client: &s3_client::S3,) -> anyhow::Result<()> {- let from_file_type: FileType = req- .from_key- .split('.')- .next_back()- .context("expected key to contain a file type")- .and_then(|s| Ok(FileType::from_str(s)?))?;-- let to_file_type: FileType = req- .to_key- .split('.')- .next_back()- .context("expected key to contain a file type")- .and_then(|s| Ok(FileType::from_str(s)?))?;+ let from_file_type = resolve_file_type(req.from_file_type, &req.from_key)?;+ let to_file_type = resolve_file_type(req.to_file_type, &req.to_key)?;let filter = get_lok_filter_from_file_types(&from_file_type, &to_file_type).context("unable to get lok filter")?;@@ -170,7 +159,41 @@ pub async fn convert(file.write_all(&file_content).context("unable to write to input file")?;- let office_path = &*LOK_PATH;+ let max_wait = conversion_timeout(&from_file_type, &to_file_type);+ run_lok_conversion(+ job_id,+ &LOK_PATH,+ &in_file_path,+ &out_file_path,+ to_file_type.as_str(),+ &filter,+ max_wait,+ )?;++ let file_content = std::fs::read(out_file_path).context("unable to read result file")?;++ s3_client+ .put(&req.to_bucket, &req.to_key, &file_content)+ .await+ .context("unable to upload file")?;++ Ok(())+}++/// Converts `in_file_path` to `out_file_path` with LibreOfficeKit in a forked+/// child process, killing it after `max_wait`.+///+/// The child process keeps a LibreOffice crash or hang from taking down the+/// worker.+pub(crate) fn run_lok_conversion(+ job_id: &str,+ office_path: &str,+ in_file_path: &str,+ out_file_path: &str,+ to_format: &str,+ filter: &str,+ max_wait: Duration,+) -> anyhow::Result<()> {let mut child_pids = vec![];match unsafe { fork() } {Ok(ForkResult::Parent { child }) => {@@ -187,25 +210,30 @@ pub async fn convert(tracing::trace!("office initialized");let document = office- .load_document(&in_file_path)+ .load_document(in_file_path).map_err(|e| anyhow::anyhow!(e)).context("unable to load document")?;tracing::trace!("document loaded");document- .save_as(&out_file_path, to_file_type.as_str(), &filter)+ .save_as(out_file_path, to_format, filter).map_err(|e| anyhow::anyhow!(e)).context("unable to save document")?;tracing::trace!("document saved");- drop(document);- drop(office);+ // The child exits right after this, so skip LibreOffice's+ // teardown: Writer can crash while destroying a document it+ // has already saved, which would fail a finished conversion.+ std::mem::forget(document);+ std::mem::forget(office);Ok(())})();match result {- Ok(_) => exit(0),+ // `_exit` skips LibreOffice's exit handlers, which can hang+ // after the teardown skipped above.+ Ok(_) => _exit(0),Err(e) => {tracing::error!(job_id=%job_id, error=?e, "unable to convert");exit(1)@@ -227,7 +255,7 @@ pub async fn convert(}// Check if we've exceeded the timeout- if start_time.elapsed().as_secs() > MAX_WAIT_TIME_SECONDS {+ if start_time.elapsed() > max_wait {tracing::error!(job_id=%job_id, "conversion timed out");// Kill any remaining child processesfor &pid in &child_pids {@@ -272,12 +300,5 @@ pub async fn convert(anyhow::bail!("conversion failed");}- let file_content = std::fs::read(out_file_path).context("unable to read result file")?;-- s3_client- .put(&req.to_bucket, &req.to_key, &file_content)- .await- .context("unable to upload file")?;-Ok(())}diff --git a/services/convert_service/src/process/test.rs b/services/convert_service/src/process/test.rsindex 41e9e51df7..16d49f1fa9 100644--- a/services/convert_service/src/process/test.rs+++ b/services/convert_service/src/process/test.rs@@ -11,3 +11,358 @@ fn docx_detection_requires_the_final_extension() {assert!(!is_docx_key("uploads/report.docx.tmp"));assert!(!is_docx_key("uploads/docx"));}++mod legacy_upgrade {+ //! Real LibreOfficeKit conversions of legacy Office fixtures, checked by+ //! opening the results in the engines that serve them.+ //!+ //! Needs LibreOffice (with Writer, Calc and Impress) on the host:+ //! `LOK_PATH=/usr/lib/libreoffice/program cargo test -p convert_service -- --ignored`.++ use std::io::Read;+ use std::path::{Path, PathBuf};+ use std::sync::Mutex;+ use std::time::Duration;++ use model::document::FileType;++ use crate::config::LokPath;+ use crate::process::convert::run_lok_conversion;+ use crate::utils::{conversion_timeout, get_lok_filter_from_file_types};++ fn fixture(name: &str) -> PathBuf {+ Path::new(env!("CARGO_MANIFEST_DIR"))+ .join("fixtures/legacy")+ .join(name)+ }++ fn fonts() -> pptx_engine::font::FontDb {+ let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../crates/pptx_engine/fonts");+ let mut db = pptx_engine::font::FontDb::new();+ let mut files: Vec<_> = std::fs::read_dir(dir)+ .expect("pptx_engine fonts")+ .filter_map(|entry| entry.ok().map(|entry| entry.path()))+ .filter(|path| {+ path.extension()+ .is_some_and(|e| e.eq_ignore_ascii_case("ttf") || e.eq_ignore_ascii_case("otf"))+ })+ .collect();+ files.sort();+ for file in files {+ db.register(std::fs::read(file).expect("font file"));+ }+ db+ }++ /// LibreOffice shares one user profile per host, so conversions run one+ /// at a time, as the worker does.+ static LOK: Mutex<()> = Mutex::new(());++ /// Upgrades a fixture and returns the OpenXML bytes.+ fn upgrade(name: &str, from: FileType, to: FileType) -> Vec<u8> {+ convert_bytes(&std::fs::read(fixture(name)).unwrap(), from, to)+ }++ fn convert_bytes(input_bytes: &[u8], from: FileType, to: FileType) -> Vec<u8> {+ let _lok = LOK.lock().unwrap_or_else(|poisoned| poisoned.into_inner());+ let lok_path = LokPath::new().expect("set LOK_PATH to LibreOffice's program directory");+ let dir = tempfile::tempdir().unwrap();+ let input = dir.path().join(format!("IN.{}", from.as_str()));+ let output = dir.path().join(format!("OUT.{}", to.as_str()));+ std::fs::write(&input, input_bytes).unwrap();++ let filter = get_lok_filter_from_file_types(&from, &to).unwrap();+ run_lok_conversion(+ "legacy-upgrade-test",+ lok_path.as_ref(),+ input.to_str().unwrap(),+ output.to_str().unwrap(),+ to.as_str(),+ &filter,+ conversion_timeout(&from, &to),+ )+ .unwrap();+ std::fs::read(output).unwrap()+ }++ fn zip_part(bytes: &[u8], name: &str) -> String {+ let mut archive = zip::ZipArchive::new(std::io::Cursor::new(bytes)).unwrap();+ let mut part = archive+ .by_name(name)+ .unwrap_or_else(|_| panic!("missing part {name}"));+ let mut text = String::new();+ part.read_to_string(&mut text).unwrap();+ text+ }++ fn zip_names(bytes: &[u8]) -> Vec<String> {+ let archive = zip::ZipArchive::new(std::io::Cursor::new(bytes)).unwrap();+ archive.file_names().map(str::to_string).collect()+ }++ fn assert_main_content_type(bytes: &[u8], content_type: &str) {+ let types = zip_part(bytes, "[Content_Types].xml");+ assert!(types.contains(content_type), "{types}");+ }++ #[test]+ #[ignore = "needs LibreOfficeKit; see module docs"]+ fn doc_upgrades_to_a_docx_the_word_engine_lays_out() {+ let docx = upgrade("memo.doc", FileType::Doc, FileType::Docx);++ assert_main_content_type(+ &docx,+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",+ );+ let xml = zip_part(&docx, "word/document.xml");+ for text in [+ "Quarterly Memo",+ "twelve percent",+ "Launched the new editor",+ "Revenue",+ "Margin",+ "Café façade naïve",+ ] {+ assert!(xml.contains(text), "missing {text:?}");+ }+ // Bold run, table, page break, list numbering and the picture survive.+ assert!(+ xml.contains("<w:b/>") || xml.contains("<w:b "),+ "bold run lost"+ );+ assert!(xml.contains("<w:tbl>"), "table lost");+ assert!(xml.contains(r#"w:type="page""#), "page break lost");+ assert!(xml.contains("<w:numPr>"), "list numbering lost");+ assert!(+ zip_names(&docx)+ .iter()+ .any(|name| name.starts_with("word/media/")),+ "picture lost"+ );++ let document = docx_engine::Document::open(docx).expect("docx engine opens the upgrade");+ let layout = document.layout(&fonts());+ assert!(layout.pages.len() >= 2, "page break should give two pages");+ }++ #[test]+ #[ignore = "needs LibreOfficeKit; see module docs"]+ fn ppt_upgrades_to_a_pptx_the_presentation_engine_renders() {+ let pptx = upgrade("deck.ppt", FileType::Ppt, FileType::Pptx);++ assert_main_content_type(+ &pptx,+ "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml",+ );+ let names = zip_names(&pptx);+ assert!(+ names.iter().any(|name| name.starts_with("ppt/media/")),+ "picture lost"+ );+ assert!(+ names+ .iter()+ .any(|name| name.starts_with("ppt/notesSlides/")),+ "speaker notes lost"+ );++ let mut presentation =+ pptx_engine::Presentation::open(pptx.clone()).expect("pptx engine opens the upgrade");+ assert_eq!(presentation.slides().len(), 4);+ let fonts = fonts();+ for index in 0..presentation.slides().len() {+ presentation+ .render_slide(index, 320, &fonts)+ .unwrap_or_else(|e| panic!("slide {} failed to render: {e}", index + 1));+ }++ let slides: String = (1..=4)+ .map(|n| zip_part(&pptx, &format!("ppt/slides/slide{n}.xml")))+ .collect();+ for text in [+ "Board Update",+ "October 2026",+ "Revenue up 12%",+ "Three new customers",+ "Numbers",+ "Margin",+ "Shape text",+ ] {+ assert!(slides.contains(text), "missing {text:?}");+ }+ assert!(slides.contains("<a:tbl>"), "table lost");+ let notes: String = names+ .iter()+ .filter(|name| name.starts_with("ppt/notesSlides/") && name.ends_with(".xml"))+ .map(|name| zip_part(&pptx, name))+ .collect();+ assert!(notes.contains("Speaker notes survive"));+ }++ #[test]+ #[ignore = "needs LibreOfficeKit; see module docs"]+ fn xls_upgrades_to_an_xlsx_with_formulas_and_sheets() {+ let xlsx = upgrade("budget.xls", FileType::Xls, FileType::Xlsx);++ assert_main_content_type(+ &xlsx,+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",+ );+ let workbook = zip_part(&xlsx, "xl/workbook.xml");+ assert!(workbook.contains(r#"name="Budget""#), "{workbook}");+ assert!(workbook.contains(r#"name="Notes""#), "{workbook}");++ let budget = zip_part(&xlsx, "xl/worksheets/sheet1.xml");+ for formula in ["SUM(B2:B13)", "SUM(D2:D13)", "B2-C2", "B13-C13"] {+ assert!(budget.contains(formula), "missing formula {formula}");+ }+ assert!(budget.contains(r#"<mergeCell ref="F1:H1""#), "merge lost");+ // Cached results are written so a reader shows values before recalculating.+ assert!(budget.contains("<v>15900</v>"), "total revenue cache lost");++ let notes = zip_part(&xlsx, "xl/worksheets/sheet2.xml");+ assert!(+ notes.contains("Budget!D15/Budget!B15"),+ "cross-sheet formula lost"+ );++ let strings = zip_part(&xlsx, "xl/sharedStrings.xml");+ for text in ["Month", "Revenue", "Merged header", "Total", "Finance"] {+ assert!(strings.contains(text), "missing {text:?}");+ }+ let styles = zip_part(&xlsx, "xl/styles.xml");+ assert!(styles.contains("#,##0.00"), "number format lost");+ }++ #[test]+ #[ignore = "needs LibreOfficeKit; see module docs"]+ fn unreadable_input_fails_instead_of_hanging() {+ let _lok = LOK.lock().unwrap_or_else(|poisoned| poisoned.into_inner());+ let lok_path = LokPath::new().expect("set LOK_PATH to LibreOffice's program directory");+ let dir = tempfile::tempdir().unwrap();+ let input = dir.path().join("IN.ppt");+ std::fs::write(&input, b"not a powerpoint file").unwrap();++ let result = run_lok_conversion(+ "legacy-upgrade-garbage",+ lok_path.as_ref(),+ input.to_str().unwrap(),+ dir.path().join("OUT.pptx").to_str().unwrap(),+ "pptx",+ "",+ Duration::from_secs(60),+ );++ assert!(result.is_err());+ }++ #[test]+ #[ignore = "needs LibreOfficeKit; see module docs"]+ fn upgraded_docx_still_exports_to_pdf() {+ // The DOCX pipeline converts every Word upload to PDF, including upgrades.+ let docx = upgrade("memo.doc", FileType::Doc, FileType::Docx);++ let pdf = convert_bytes(&docx, FileType::Docx, FileType::Pdf);++ assert!(pdf.starts_with(b"%PDF-"));+ assert!(pdf.len() > 1_000);+ }++ #[test]+ #[ignore = "needs LibreOfficeKit; see module docs"]+ fn upgraded_pptx_still_exports_to_pdf() {+ let pptx = upgrade("deck.ppt", FileType::Ppt, FileType::Pptx);++ let pdf = convert_bytes(&pptx, FileType::Pptx, FileType::Pdf);++ assert!(pdf.starts_with(b"%PDF-"));+ }+}++mod conversion_table {+ use model::document::FileType;++ use crate::utils::{conversion_timeout, get_lok_filter_from_file_types, resolve_file_type};++ #[test]+ fn legacy_upgrades_are_supported() {+ for (from, to) in [+ (FileType::Doc, FileType::Docx),+ (FileType::Xls, FileType::Xlsx),+ (FileType::Ppt, FileType::Pptx),+ ] {+ assert_eq!(get_lok_filter_from_file_types(&from, &to).unwrap(), "");+ assert_eq!(conversion_timeout(&from, &to).as_secs(), 120);+ }+ }++ #[test]+ fn existing_exports_keep_their_filters() {+ assert_eq!(+ get_lok_filter_from_file_types(&FileType::Docx, &FileType::Pdf).unwrap(),+ "writer_pdf_Export"+ );+ assert_eq!(+ get_lok_filter_from_file_types(&FileType::Xlsx, &FileType::Html).unwrap(),+ "calc_HTML_WebQuery"+ );+ assert_eq!(+ get_lok_filter_from_file_types(&FileType::Pptx, &FileType::Pdf).unwrap(),+ "impress_pdf_Export"+ );+ assert_eq!(+ conversion_timeout(&FileType::Docx, &FileType::Pdf).as_secs(),+ 30+ );+ }++ #[test]+ fn unsupported_pairs_are_rejected() {+ for (from, to) in [+ (FileType::Doc, FileType::Pdf),+ (FileType::Ppt, FileType::Docx),+ (FileType::Docx, FileType::Doc),+ (FileType::Xlsm, FileType::Xlsx),+ ] {+ assert!(+ get_lok_filter_from_file_types(&from, &to).is_err(),+ "{from}->{to}"+ );+ }+ }++ #[test]+ fn explicit_types_win_over_key_extensions() {+ assert_eq!(+ resolve_file_type(Some(FileType::Ppt), "owner/doc/12").unwrap(),+ FileType::Ppt+ );+ assert_eq!(+ resolve_file_type(Some(FileType::Doc), "owner/doc/7.docx").unwrap(),+ FileType::Doc+ );+ }++ #[test]+ fn key_extensions_are_used_without_explicit_types() {+ assert_eq!(+ resolve_file_type(None, "owner/doc/converted.pdf").unwrap(),+ FileType::Pdf+ );+ assert_eq!(+ resolve_file_type(None, "macro|[email protected]/doc/upgraded.PPTX").unwrap(),+ FileType::Pptx+ );+ assert_eq!(+ resolve_file_type(None, "owner/doc/7.docx").unwrap(),+ FileType::Docx+ );+ }++ #[test]+ fn versioned_keys_need_explicit_types() {+ assert!(resolve_file_type(None, "owner/doc/12").is_err());+ // A dotted owner segment is not an extension.+ assert!(resolve_file_type(None, "macro|[email protected]/doc/12").is_err());+ }+}diff --git a/services/convert_service/src/utils.rs b/services/convert_service/src/utils.rsindex d0de76b00b..abd3b5ca31 100644--- a/services/convert_service/src/utils.rs+++ b/services/convert_service/src/utils.rs@@ -1,3 +1,6 @@+use std::str::FromStr;+use std::time::Duration;+use anyhow::Context;use model::document::FileType;@@ -12,31 +15,55 @@ pub fn cleanup_folder(job_id: &str) -> anyhow::Result<()> {Ok(())}+/// LibreOfficeKit filter options for a supported conversion.+///+/// LOK picks the export filter from the target format (`save_as`'s format+/// argument); this returns the options string passed alongside it.pub fn get_lok_filter_from_file_types(from_file_type: &FileType,to_file_type: &FileType,) -> anyhow::Result<String> {- match from_file_type {- FileType::Docx => match to_file_type {- FileType::Pdf => Ok("writer_pdf_Export".to_string()),- _ => Err(anyhow::anyhow!(- "unsupported conversion of {from_file_type} to {to_file_type}"- )),- },- FileType::Xlsx => match to_file_type {- FileType::Html => Ok("calc_HTML_WebQuery".to_string()),- _ => Err(anyhow::anyhow!(- "unsupported conversion of {from_file_type} to {to_file_type}"- )),- },- FileType::Pptx => match to_file_type {- FileType::Pdf => Ok("impress_pdf_Export".to_string()),- _ => Err(anyhow::anyhow!(- "unsupported conversion of {from_file_type} to {to_file_type}"- )),- },+ match (from_file_type, to_file_type) {+ (FileType::Docx, FileType::Pdf) => Ok("writer_pdf_Export".to_string()),+ (FileType::Xlsx, FileType::Html) => Ok("calc_HTML_WebQuery".to_string()),+ (FileType::Pptx, FileType::Pdf) => Ok("impress_pdf_Export".to_string()),+ // Legacy binary Office upgrades. The OOXML export filters+ // ("MS Word 2007 XML", "Calc MS Excel 2007 XML",+ // "Impress MS PowerPoint 2007 XML") need no options.+ (FileType::Doc, FileType::Docx)+ | (FileType::Xls, FileType::Xlsx)+ | (FileType::Ppt, FileType::Pptx) => Ok(String::new()),_ => Err(anyhow::anyhow!(- "unsupported conversion of {from_file_type} for conversion"+ "unsupported conversion of {from_file_type} to {to_file_type}")),}}++/// How long a conversion may run before its child process is killed.+///+/// Upgrading a legacy deck or workbook re-encodes every embedded image and+/// sheet, so it gets more time than an export.+pub fn conversion_timeout(from_file_type: &FileType, to_file_type: &FileType) -> Duration {+ match (from_file_type, to_file_type) {+ (FileType::Doc, FileType::Docx)+ | (FileType::Xls, FileType::Xlsx)+ | (FileType::Ppt, FileType::Pptx) => Duration::from_secs(120),+ _ => Duration::from_secs(30),+ }+}++/// The file type of a conversion side: the explicit type when the message+/// carries one, else the key's extension.+///+/// Versioned document keys (`{owner}/{document_id}/{version_id}`) have no+/// extension, so jobs reading them name the type explicitly.+pub fn resolve_file_type(explicit: Option<FileType>, key: &str) -> anyhow::Result<FileType> {+ if let Some(file_type) = explicit {+ return Ok(file_type);+ }+ let file_name = key.rsplit('/').next().unwrap_or(key);+ let (_, extension) = file_name+ .rsplit_once('.')+ .context("expected key to contain a file type")?;+ Ok(FileType::from_str(extension)?)+}diff --git a/services/document_upload_finalizer_handler/Cargo.toml b/services/document_upload_finalizer_handler/Cargo.tomlindex 01db4abe12..374416a8fb 100644--- a/services/document_upload_finalizer_handler/Cargo.toml+++ b/services/document_upload_finalizer_handler/Cargo.toml@@ -22,12 +22,17 @@ lexical_client = { path = "../../crates/lexical_client" }macro_aws_config = { path = "../../crates/macro_aws_config", features = ["s3"] }macro_entrypoint = { path = "../../crates/macro_entrypoint" }macro_env_var = { path = "../../crates/macro_env_var" }+macro_queues = { path = "../../crates/macro_queues" }+macro_uuid = { path = "../../crates/macro_uuid" }model = { path = "../../crates/model" }+model_owner = { path = "../../crates/model_owner" }s3_key = { path = "../../crates/s3_key" }macro_service_urls = { path = "../../crates/macro_service_urls" }serde = { workspace = true }serde_json = { workspace = true }+sha2 = { workspace = true }sqlx = { workspace = true, features = ["postgres", "runtime-tokio-rustls"] }+sqs_client = { path = "../../crates/sqs_client" }sync_service_client = { path = "../../crates/sync_service_client" }tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }tracing = { workspace = true }diff --git a/services/document_upload_finalizer_handler/src/app.rs b/services/document_upload_finalizer_handler/src/app.rsindex 662eca6c6c..c1ff684c1b 100644--- a/services/document_upload_finalizer_handler/src/app.rs+++ b/services/document_upload_finalizer_handler/src/app.rs@@ -1,7 +1,10 @@+use documents::domain::legacy_office_upgrade::{+ LegacyOfficeUpgradeRepoPort, LegacyOfficeUpgradeStoragePort, LegacyOfficeUpgrader,+};use documents::domain::ports::markdown::MarkdownInitializationPort;use documents::domain::upload_finalize::{UploadFinalizeDocumentPort, UploadedDocumentFinalizer};use model::document::FileType;-use s3_key::DocumentKey;+use s3_key::{DocumentKey, UpgradedOfficeFormat};use crate::ports::{DocumentObjectReader, DocumentUploadMetadataPort};@@ -15,25 +18,36 @@ pub struct ObjectCreated {}/// Application use case for finalizing document uploads from object-created events.-pub struct DocumentUploadFinalizer<P, O> {+pub struct DocumentUploadFinalizer<P, O, U> {document_port: P,object_reader: O,+ upgrade_storage: U,}-impl<P, O> DocumentUploadFinalizer<P, O> {+impl<P, O, U> DocumentUploadFinalizer<P, O, U> {/// Construct the upload finalization use case.- pub fn new(document_port: P, object_reader: O) -> Self {+ pub fn new(document_port: P, object_reader: O, upgrade_storage: U) -> Self {Self {document_port,object_reader,+ upgrade_storage,}}}-impl<P, O> DocumentUploadFinalizer<P, O>+fn upgraded_file_type(format: UpgradedOfficeFormat) -> FileType {+ match format {+ UpgradedOfficeFormat::Docx => FileType::Docx,+ UpgradedOfficeFormat::Pptx => FileType::Pptx,+ UpgradedOfficeFormat::Xlsx => FileType::Xlsx,+ }+}++impl<P, O, U> DocumentUploadFinalizer<P, O, U>where- P: DocumentUploadMetadataPort + UploadFinalizeDocumentPort,+ P: DocumentUploadMetadataPort + UploadFinalizeDocumentPort + LegacyOfficeUpgradeRepoPort,O: DocumentObjectReader,+ U: LegacyOfficeUpgradeStoragePort,{/// Handle one object-created event.#[tracing::instrument(skip(self, markdown_initializer), err)]@@ -55,7 +69,9 @@ wherelet is_finalizable_key = matches!(document_key,- DocumentKey::Versioned { .. } | DocumentKey::ConvertedPdf { .. }+ DocumentKey::Versioned { .. }+ | DocumentKey::ConvertedPdf { .. }+ | DocumentKey::UpgradedOffice { .. });if !is_finalizable_key {tracing::trace!(key=%event.key, ?document_key, "skipping non-finalizable document storage key");@@ -86,17 +102,37 @@ where};let finalizer = UploadedDocumentFinalizer::new(&self.document_port, markdown_initializer);+ let upgrader = LegacyOfficeUpgrader::new(&self.document_port, &self.upgrade_storage);let result = match document_key {DocumentKey::ConvertedPdf { .. } => {finalizer.finalize_converted_pdf_document(&document_context).await}- DocumentKey::Versioned { .. } => {- finalizer+ DocumentKey::Versioned { version_id, .. } => {+ // The legacy original stays ready (downloadable) while its+ // OpenXML upgrade is produced.+ match finalizer.finalize_uploaded_document(&document_context, markdown.as_deref()).await+ {+ Ok(()) => upgrader+ .request_upgrade(&document_context, version_id)+ .await+ .map(|requested| {+ if requested {+ tracing::info!(%document_id, version_id, "requested legacy office upgrade");+ }+ }),+ Err(error) => Err(error),+ }}+ DocumentKey::UpgradedOffice { format, .. } => upgrader+ .apply_upgrade(&document_context, upgraded_file_type(format))+ .await+ .map(|outcome| {+ tracing::info!(%document_id, ?outcome, "applied legacy office upgrade");+ }),_ => unreachable!("non-finalizable keys returned earlier"),};@@ -109,3 +145,6 @@ where}}}++#[cfg(test)]+mod tests;diff --git a/services/document_upload_finalizer_handler/src/app/tests.rs b/services/document_upload_finalizer_handler/src/app/tests.rsnew file mode 100644index 0000000000..7ad266550d--- /dev/null+++ b/services/document_upload_finalizer_handler/src/app/tests.rs@@ -0,0 +1,365 @@+use std::str::FromStr;+use std::sync::Mutex;++use documents::domain::content::{DocumentContent, DocumentContentLocation, DocumentContentState};+use documents::domain::legacy_office_upgrade::{+ LegacyOfficeUpgradeRequest, UpgradedObjectDestination,+};+use documents::domain::models::DocumentError;+use model::document::DocumentBasic;+use model_owner::Owner;++use super::*;++const OWNER: &str = "macro|[email protected]";+const DOCUMENT_ID: &str = "01a0914f-1fde-7873-80ba-6eef315d3b50";+const BUCKET: &str = "document-storage";++#[derive(Clone, Debug, PartialEq)]+enum Call {+ SetContent(DocumentContentState, Option<DocumentContentLocation>),+ RequestUpgrade(LegacyOfficeUpgradeRequest),+ Promote(FileType, UpgradedObjectDestination),+ Swap(FileType, FileType),+ CreateInstance,+ CreateBom,+}++#[derive(Default)]+struct Log(Mutex<Vec<Call>>);++impl Log {+ fn push(&self, call: Call) {+ self.0.lock().unwrap().push(call);+ }+ fn calls(&self) -> Vec<Call> {+ self.0.lock().unwrap().clone()+ }+}++struct FakeDocuments<'a> {+ log: &'a Log,+ file_type: Mutex<Option<String>>,+ content: DocumentContent,+}++impl FakeDocuments<'_> {+ fn document(&self) -> DocumentBasic {+ DocumentBasic {+ document_id: DOCUMENT_ID.to_string(),+ document_name: "Upload".to_string(),+ owner: Owner::from_principal_str(OWNER).unwrap(),+ file_type: self.file_type.lock().unwrap().clone(),+ sub_type: None,+ branched_from_id: None,+ branched_from_version_id: None,+ document_family_id: None,+ project_id: None,+ deleted_at: None,+ }+ }+}++impl DocumentUploadMetadataPort for FakeDocuments<'_> {+ async fn get_basic_document(+ &self,+ document_id: &str,+ ) -> Result<Option<DocumentBasic>, DocumentError> {+ assert_eq!(document_id, DOCUMENT_ID);+ Ok(Some(self.document()))+ }+}++impl UploadFinalizeDocumentPort for FakeDocuments<'_> {+ async fn get_document_content(+ &self,+ _document_context: &DocumentBasic,+ ) -> Result<DocumentContent, DocumentError> {+ Ok(self.content.clone())+ }++ async fn mark_document_uploaded(&self, _document_id: &str) -> Result<(), DocumentError> {+ Ok(())+ }++ async fn set_document_content(+ &self,+ _document_id: &str,+ content: DocumentContent,+ ) -> Result<(), DocumentError> {+ self.log+ .push(Call::SetContent(content.state, content.location));+ Ok(())+ }+}++impl LegacyOfficeUpgradeRepoPort for FakeDocuments<'_> {+ async fn create_document_instance(+ &self,+ _document_id: &str,+ _sha: &str,+ ) -> Result<i64, DocumentError> {+ self.log.push(Call::CreateInstance);+ Ok(99)+ }++ async fn delete_document_instance(&self, _version_id: i64) -> Result<(), DocumentError> {+ Ok(())+ }++ async fn create_document_bom(&self, _document_id: &str) -> Result<i64, DocumentError> {+ self.log.push(Call::CreateBom);+ Ok(5)+ }++ async fn delete_document_bom(&self, _bom_id: i64) -> Result<(), DocumentError> {+ Ok(())+ }++ async fn swap_document_file_type(+ &self,+ _document_id: &str,+ from: FileType,+ to: FileType,+ ) -> Result<bool, DocumentError> {+ self.log.push(Call::Swap(from, to));+ let mut stored = self.file_type.lock().unwrap();+ if stored.as_deref() != Some(from.as_str()) {+ return Ok(false);+ }+ *stored = Some(to.as_str().to_string());+ Ok(true)+ }++ async fn set_document_content(+ &self,+ _document_id: &str,+ content: DocumentContent,+ ) -> Result<(), DocumentError> {+ self.log+ .push(Call::SetContent(content.state, content.location));+ Ok(())+ }+}++struct FakeObjects;++impl DocumentObjectReader for FakeObjects {+ async fn read_utf8_object(&self, _bucket: &str, _key: &str) -> Result<String, anyhow::Error> {+ Ok("# markdown".to_string())+ }+}++struct FakeUpgradeStorage<'a> {+ log: &'a Log,+}++impl LegacyOfficeUpgradeStoragePort for FakeUpgradeStorage<'_> {+ async fn request_upgrade(+ &self,+ request: &LegacyOfficeUpgradeRequest,+ ) -> Result<(), DocumentError> {+ self.log.push(Call::RequestUpgrade(request.clone()));+ Ok(())+ }++ async fn upgraded_object_sha(+ &self,+ _owner: &Owner,+ _document_id: &str,+ _target: FileType,+ ) -> Result<String, DocumentError> {+ Ok("sha".to_string())+ }++ async fn promote_upgraded_object(+ &self,+ _owner: &Owner,+ _document_id: &str,+ target: FileType,+ destination: UpgradedObjectDestination,+ ) -> Result<(), DocumentError> {+ self.log.push(Call::Promote(target, destination));+ Ok(())+ }+}++struct NoMarkdown;++impl MarkdownInitializationPort for NoMarkdown {+ async fn initialize_existing_markdown(+ &self,+ _document_id: &str,+ _markdown: &str,+ ) -> Result<Vec<u8>, DocumentError> {+ Ok(Vec::new())+ }+}++async fn handle(file_type: Option<&str>, content: DocumentContent, key: String) -> Vec<Call> {+ let log = Log::default();+ let finalizer = DocumentUploadFinalizer::new(+ FakeDocuments {+ log: &log,+ file_type: Mutex::new(file_type.map(str::to_string)),+ content,+ },+ FakeObjects,+ FakeUpgradeStorage { log: &log },+ );+ finalizer+ .handle_object_created(+ ObjectCreated {+ bucket: BUCKET.to_string(),+ key,+ },+ &NoMarkdown,+ )+ .await+ .unwrap();+ log.calls()+}++fn versioned_key(version_id: i64) -> String {+ format!("{OWNER}/{DOCUMENT_ID}/{version_id}")+}++fn upgraded_key(extension: &str) -> String {+ format!("{OWNER}/{DOCUMENT_ID}/upgraded.{extension}")+}++#[tokio::test]+async fn legacy_upload_is_finalized_then_upgrade_requested() {+ for (legacy, target) in [+ ("ppt", FileType::Pptx),+ ("doc", FileType::Docx),+ ("xls", FileType::Xlsx),+ ] {+ let calls = handle(Some(legacy), DocumentContent::pending(), versioned_key(12)).await;++ assert_eq!(+ calls,+ vec![+ Call::SetContent(+ DocumentContentState::Ready,+ Some(DocumentContentLocation::ObjectStorage)+ ),+ Call::RequestUpgrade(LegacyOfficeUpgradeRequest {+ owner: Owner::from_principal_str(OWNER).unwrap(),+ document_id: DOCUMENT_ID.to_string(),+ source_version_id: 12,+ from: FileType::from_str(legacy).unwrap(),+ to: target,+ }),+ ],+ "{legacy}"+ );+ }+}++#[tokio::test]+async fn modern_uploads_request_no_upgrade() {+ for file_type in ["pptx", "xlsx", "xlsm", "pdf"] {+ let calls = handle(+ Some(file_type),+ DocumentContent::pending(),+ versioned_key(3),+ )+ .await;++ assert!(+ !calls+ .iter()+ .any(|call| matches!(call, Call::RequestUpgrade(_))),+ "{file_type}: {calls:?}"+ );+ }+}++#[tokio::test]+async fn copied_upgrade_version_requests_nothing() {+ // The copy into a versioned key fires after the type was swapped.+ let calls = handle(+ Some("pptx"),+ DocumentContent::ready(DocumentContentLocation::ObjectStorage),+ versioned_key(99),+ )+ .await;++ assert!(calls.is_empty(), "{calls:?}");+}++#[tokio::test]+async fn upgraded_presentation_becomes_the_current_version() {+ let calls = handle(+ Some("ppt"),+ DocumentContent::ready(DocumentContentLocation::ObjectStorage),+ upgraded_key("pptx"),+ )+ .await;++ assert_eq!(+ calls,+ vec![+ Call::CreateInstance,+ Call::Swap(FileType::Ppt, FileType::Pptx),+ Call::Promote(+ FileType::Pptx,+ UpgradedObjectDestination::DocumentVersion { version_id: 99 }+ ),+ Call::SetContent(+ DocumentContentState::Ready,+ Some(DocumentContentLocation::ObjectStorage)+ ),+ ]+ );+}++#[tokio::test]+async fn upgraded_word_document_is_staged_for_the_docx_pipeline() {+ let calls = handle(+ Some("doc"),+ DocumentContent::ready(DocumentContentLocation::ObjectStorage),+ upgraded_key("docx"),+ )+ .await;++ assert_eq!(+ calls,+ vec![+ Call::CreateBom,+ Call::Swap(FileType::Doc, FileType::Docx),+ Call::SetContent(+ DocumentContentState::Pending,+ Some(DocumentContentLocation::ConvertedPdf)+ ),+ Call::Promote(+ FileType::Docx,+ UpgradedObjectDestination::DocxStaging { bom_id: 5 }+ ),+ ]+ );+}++#[tokio::test]+async fn redelivered_upgrade_is_skipped() {+ let calls = handle(+ Some("xlsx"),+ DocumentContent::ready(DocumentContentLocation::ObjectStorage),+ upgraded_key("xlsx"),+ )+ .await;++ assert!(calls.is_empty(), "{calls:?}");+}++#[tokio::test]+async fn unparseable_keys_are_ignored() {+ for key in [+ format!("{OWNER}/{DOCUMENT_ID}/upgraded.doc"),+ format!("{OWNER}/{DOCUMENT_ID}/notes.txt"),+ ] {+ let calls = handle(Some("doc"), DocumentContent::pending(), key.clone()).await;+ assert!(calls.is_empty(), "{key}");+ }+}diff --git a/services/document_upload_finalizer_handler/src/outbound.rs b/services/document_upload_finalizer_handler/src/outbound.rsindex fc24ecab8e..6387d7c6cc 100644--- a/services/document_upload_finalizer_handler/src/outbound.rs+++ b/services/document_upload_finalizer_handler/src/outbound.rs@@ -1,10 +1,22 @@use documents::domain::content::DocumentContent;+use documents::domain::legacy_office_upgrade::{+ LegacyOfficeUpgradeRepoPort, LegacyOfficeUpgradeRequest, LegacyOfficeUpgradeStoragePort,+ UpgradedObjectDestination,+};use documents::domain::models::DocumentError;use documents::domain::upload_finalize::{RepoUploadFinalizePort, UploadFinalizeDocumentPort};use documents::outbound::pg_document_repo::PgDocumentRepo;use documents::outbound::s3_utf8_object_reader::S3Utf8ObjectReader;use entity_registry::BotFacts;-use model::document::DocumentBasic;+use model::convert::ConvertQueueMessage;+use model::document::{DocumentBasic, FileType};+use model_owner::Owner;+use s3_key::{+ UpgradedOfficeFormat, build_cloud_storage_bucket_document_key,+ build_docx_staging_bucket_document_key, build_upgraded_office_document_key,+ document_key_url_path,+};+use sha2::{Digest, Sha256};use crate::ports::{DocumentObjectReader, DocumentUploadMetadataPort};@@ -88,3 +100,208 @@ impl<B: BotFacts + Clone + 'static> UploadFinalizeDocumentPort for PgDocumentUpl.await}}++impl<B: BotFacts + Clone + 'static> LegacyOfficeUpgradeRepoPort for PgDocumentUploadPort<B> {+ async fn create_document_instance(+ &self,+ document_id: &str,+ sha: &str,+ ) -> Result<i64, DocumentError> {+ self.repo.create_document_instance(document_id, sha).await+ }++ async fn delete_document_instance(&self, version_id: i64) -> Result<(), DocumentError> {+ self.repo.delete_document_instance(version_id).await+ }++ async fn create_document_bom(&self, document_id: &str) -> Result<i64, DocumentError> {+ self.repo.create_document_bom(document_id).await+ }++ async fn delete_document_bom(&self, bom_id: i64) -> Result<(), DocumentError> {+ self.repo.delete_document_bom(bom_id).await+ }++ async fn swap_document_file_type(+ &self,+ document_id: &str,+ from: FileType,+ to: FileType,+ ) -> Result<bool, DocumentError> {+ self.repo+ .swap_document_file_type(document_id, from, to)+ .await+ }++ async fn set_document_content(+ &self,+ document_id: &str,+ content: DocumentContent,+ ) -> Result<(), DocumentError> {+ LegacyOfficeUpgradeRepoPort::set_document_content(&self.repo, document_id, content).await+ }+}++/// S3 and convert-queue backed storage for legacy Office upgrades.+#[derive(Clone)]+pub struct S3LegacyOfficeUpgradeStorage {+ s3_client: aws_sdk_s3::Client,+ sqs_client: sqs_client::SQS,+ document_storage_bucket: String,+ docx_upload_bucket: String,+}++impl S3LegacyOfficeUpgradeStorage {+ /// Construct the upgrade storage adapter.+ pub fn new(+ s3_client: aws_sdk_s3::Client,+ sqs_client: sqs_client::SQS,+ document_storage_bucket: String,+ docx_upload_bucket: String,+ ) -> Self {+ Self {+ s3_client,+ sqs_client,+ document_storage_bucket,+ docx_upload_bucket,+ }+ }+}++fn upgraded_format(target: FileType) -> Result<UpgradedOfficeFormat, DocumentError> {+ match target {+ FileType::Docx => Ok(UpgradedOfficeFormat::Docx),+ FileType::Pptx => Ok(UpgradedOfficeFormat::Pptx),+ FileType::Xlsx => Ok(UpgradedOfficeFormat::Xlsx),+ _ => Err(DocumentError::BadRequest(format!(+ "{target} is not an upgrade target"+ ))),+ }+}++fn storage_error(context: &str, error: impl std::fmt::Debug) -> DocumentError {+ DocumentError::Internal(anyhow::anyhow!("{context}: {error:?}"))+}++/// The convert-queue message that writes a legacy original's OpenXML upgrade.+pub fn upgrade_convert_message(+ request: &LegacyOfficeUpgradeRequest,+ document_storage_bucket: &str,+ job_id: String,+) -> Result<ConvertQueueMessage, DocumentError> {+ Ok(ConvertQueueMessage {+ job_id,+ from_bucket: document_storage_bucket.to_string(),+ to_bucket: document_storage_bucket.to_string(),+ from_key: build_cloud_storage_bucket_document_key(+ &request.owner,+ &request.document_id,+ request.source_version_id,+ ),+ to_key: build_upgraded_office_document_key(+ &request.owner,+ &request.document_id,+ upgraded_format(request.to)?,+ ),+ // Versioned keys have no extension, so the types travel explicitly.+ from_file_type: Some(request.from),+ to_file_type: Some(request.to),+ })+}++/// The bucket and key an upgraded object is copied to.+pub fn upgraded_object_destination(+ owner: &Owner,+ document_id: &str,+ destination: UpgradedObjectDestination,+ document_storage_bucket: &str,+ docx_upload_bucket: &str,+) -> (String, String) {+ match destination {+ UpgradedObjectDestination::DocumentVersion { version_id } => (+ document_storage_bucket.to_string(),+ build_cloud_storage_bucket_document_key(owner, document_id, version_id),+ ),+ UpgradedObjectDestination::DocxStaging { bom_id } => (+ docx_upload_bucket.to_string(),+ build_docx_staging_bucket_document_key(owner, document_id, bom_id),+ ),+ }+}++impl LegacyOfficeUpgradeStoragePort for S3LegacyOfficeUpgradeStorage {+ async fn request_upgrade(+ &self,+ request: &LegacyOfficeUpgradeRequest,+ ) -> Result<(), DocumentError> {+ let message = upgrade_convert_message(+ request,+ &self.document_storage_bucket,+ macro_uuid::generate_uuid_v7().to_string(),+ )?;+ self.sqs_client+ .enqueue_convert_queue_message(message)+ .await+ .map_err(|error| storage_error("failed to enqueue legacy office upgrade", error))+ }++ async fn upgraded_object_sha(+ &self,+ owner: &Owner,+ document_id: &str,+ target: FileType,+ ) -> Result<String, DocumentError> {+ let key = build_upgraded_office_document_key(owner, document_id, upgraded_format(target)?);+ let object = self+ .s3_client+ .get_object()+ .bucket(&self.document_storage_bucket)+ .key(&key)+ .send()+ .await+ .map_err(|error| storage_error("failed to read upgraded office object", error))?;+ let bytes = object+ .body+ .collect()+ .await+ .map_err(|error| storage_error("failed to read upgraded office object", error))?+ .into_bytes();+ Ok(format!("{:x}", Sha256::digest(&bytes)))+ }++ async fn promote_upgraded_object(+ &self,+ owner: &Owner,+ document_id: &str,+ target: FileType,+ destination: UpgradedObjectDestination,+ ) -> Result<(), DocumentError> {+ let source_key =+ build_upgraded_office_document_key(owner, document_id, upgraded_format(target)?);+ let (bucket, key) = upgraded_object_destination(+ owner,+ document_id,+ destination,+ &self.document_storage_bucket,+ &self.docx_upload_bucket,+ );+ self.s3_client+ .copy_object()+ .copy_source(format!(+ "{}/{}",+ self.document_storage_bucket,+ document_key_url_path(&source_key)+ ))+ .bucket(bucket)+ .key(key)+ .content_type(target.mime_type())+ .metadata_directive(aws_sdk_s3::types::MetadataDirective::Replace)+ .send()+ .await+ .map_err(|error| storage_error("failed to copy upgraded office object", error))?;+ Ok(())+ }+}++#[cfg(test)]+mod tests;diff --git a/services/document_upload_finalizer_handler/src/outbound/tests.rs b/services/document_upload_finalizer_handler/src/outbound/tests.rsnew file mode 100644index 0000000000..f86bb638c1--- /dev/null+++ b/services/document_upload_finalizer_handler/src/outbound/tests.rs@@ -0,0 +1,103 @@+use super::*;++const OWNER: &str = "macro|[email protected]";+const DOCUMENT_ID: &str = "01a0914f-1fde-7873-80ba-6eef315d3b50";++fn owner() -> Owner {+ Owner::from_principal_str(OWNER).unwrap()+}++fn request(from: FileType, to: FileType) -> LegacyOfficeUpgradeRequest {+ LegacyOfficeUpgradeRequest {+ owner: owner(),+ document_id: DOCUMENT_ID.to_string(),+ source_version_id: 314,+ from,+ to,+ }+}++#[test]+fn convert_message_reads_the_version_and_writes_the_upgraded_key() {+ for (from, to, extension) in [+ (FileType::Ppt, FileType::Pptx, "pptx"),+ (FileType::Doc, FileType::Docx, "docx"),+ (FileType::Xls, FileType::Xlsx, "xlsx"),+ ] {+ let message =+ upgrade_convert_message(&request(from, to), "doc-storage", "job".to_string()).unwrap();++ assert_eq!(message.job_id, "job");+ assert_eq!(message.from_bucket, "doc-storage");+ assert_eq!(message.to_bucket, "doc-storage");+ assert_eq!(message.from_key, format!("{OWNER}/{DOCUMENT_ID}/314"));+ assert_eq!(+ message.to_key,+ format!("{OWNER}/{DOCUMENT_ID}/upgraded.{extension}")+ );+ assert_eq!(message.from_file_type, Some(from));+ assert_eq!(message.to_file_type, Some(to));+ }+}++#[test]+fn convert_message_round_trips_through_json() {+ let message = upgrade_convert_message(+ &request(FileType::Doc, FileType::Docx),+ "doc-storage",+ "job".to_string(),+ )+ .unwrap();++ let json = serde_json::to_value(&message).unwrap();+ assert_eq!(json["from_file_type"], "doc");+ assert_eq!(json["to_file_type"], "docx");+ let parsed: ConvertQueueMessage = serde_json::from_value(json).unwrap();+ assert_eq!(parsed.from_file_type, Some(FileType::Doc));+}++#[test]+fn convert_message_rejects_non_upgrade_targets() {+ assert!(+ upgrade_convert_message(+ &request(FileType::Pdf, FileType::Pdf),+ "doc-storage",+ "job".to_string()+ )+ .is_err()+ );+}++#[test]+fn versions_are_copied_into_document_storage() {+ assert_eq!(+ upgraded_object_destination(+ &owner(),+ DOCUMENT_ID,+ UpgradedObjectDestination::DocumentVersion { version_id: 77 },+ "doc-storage",+ "docx-upload",+ ),+ (+ "doc-storage".to_string(),+ format!("{OWNER}/{DOCUMENT_ID}/77")+ )+ );+}++#[test]+fn word_upgrades_are_staged_in_the_docx_bucket() {+ assert_eq!(+ upgraded_object_destination(+ &owner(),+ DOCUMENT_ID,+ UpgradedObjectDestination::DocxStaging { bom_id: 8 },+ "doc-storage",+ "docx-upload",+ ),+ (+ "docx-upload".to_string(),+ format!("{OWNER}/{DOCUMENT_ID}/8.docx")+ )+ );+}diff --git a/services/document_upload_finalizer_handler/src/runtime.rs b/services/document_upload_finalizer_handler/src/runtime.rsindex 0ec0f07482..b89cbbec29 100644--- a/services/document_upload_finalizer_handler/src/runtime.rs+++ b/services/document_upload_finalizer_handler/src/runtime.rs@@ -11,17 +11,23 @@ use sqlx::postgres::PgPoolOptions;use sync_service_client::SyncServiceClient;use crate::app::{DocumentUploadFinalizer, ObjectCreated};-use crate::outbound::{PgDocumentUploadPort, S3DocumentObjectReader};+use crate::outbound::{PgDocumentUploadPort, S3DocumentObjectReader, S3LegacyOfficeUpgradeStorage};env_vars! {struct DatabaseUrl;struct InternalApiSecretKey;struct SyncServiceAuthKey;+ struct DocumentStorageBucket;+ struct DocxDocumentUploadBucket;}/// Concrete app context used by Lambda and local worker entrypoints.pub struct AppContext {- finalizer: DocumentUploadFinalizer<PgDocumentUploadPort<PgBotsRepo>, S3DocumentObjectReader>,+ finalizer: DocumentUploadFinalizer<+ PgDocumentUploadPort<PgBotsRepo>,+ S3DocumentObjectReader,+ S3LegacyOfficeUpgradeStorage,+ >,lexical_client: LexicalClient,sync_service_client: SyncServiceClient,}@@ -36,6 +42,12 @@ impl AppContext {let sync_service_auth_key = SyncServiceAuthKey::new().context("SYNC_SERVICE_AUTH_KEY must be provided")?.to_string();+ let document_storage_bucket = DocumentStorageBucket::new()+ .context("DOCUMENT_STORAGE_BUCKET must be provided")?+ .to_string();+ let docx_upload_bucket = DocxDocumentUploadBucket::new()+ .context("DOCX_DOCUMENT_UPLOAD_BUCKET must be provided")?+ .to_string();let lexical_service_url = LexicalServiceUrl::new()?.to_string();let sync_service_url = SyncServiceUrl::new()?.to_string();@@ -49,8 +61,20 @@ impl AppContext {OwnedEntityRegistrar::new(OwnerGrantPolicy::new(PgBotsRepo::new(db_pool.clone())));let repo = PgDocumentRepo::new(db_pool, registrar);let document_port = PgDocumentUploadPort::new(repo);- let object_reader = S3DocumentObjectReader::new(macro_aws_config::s3_client().await);- let finalizer = DocumentUploadFinalizer::new(document_port, object_reader);+ let s3_client = macro_aws_config::s3_client().await;+ let object_reader = S3DocumentObjectReader::new(s3_client.clone());+ let convert_queue = macro_queues::ConvertQueue::new();+ let sqs_client = sqs_client::SQS::new(aws_sdk_sqs::Client::new(+ ¯o_aws_config::get_macro_aws_config().await,+ ))+ .convert_queue(&convert_queue);+ let upgrade_storage = S3LegacyOfficeUpgradeStorage::new(+ s3_client,+ sqs_client,+ document_storage_bucket,+ docx_upload_bucket,+ );+ let finalizer = DocumentUploadFinalizer::new(document_port, object_reader, upgrade_storage);Ok(Self {finalizer,diff --git a/services/docx_unzip_handler/src/service/document/process_document.rs b/services/docx_unzip_handler/src/service/document/process_document.rsindex 09b1769dac..d4fdd58c2c 100644--- a/services/docx_unzip_handler/src/service/document/process_document.rs+++ b/services/docx_unzip_handler/src/service/document/process_document.rs@@ -59,6 +59,8 @@ pub async fn process(&document_key_parts.document_id,),to_bucket: ctx.config.document_storage_bucket.clone(),+ from_file_type: None,+ to_file_type: None,}).await{diff --git a/services/search_upload_handler/src/handler.rs b/services/search_upload_handler/src/handler.rsindex 89b660e8f2..ce9090cdee 100644--- a/services/search_upload_handler/src/handler.rs+++ b/services/search_upload_handler/src/handler.rs@@ -32,9 +32,12 @@ pub async fn handler(}};+ // An upgraded legacy Office file is an intermediate: its copy into a+ // versioned key relays the content upload.if document_key.is_temp()|| document_key.is_bom_part()|| document_key.is_sync_service_snapshot()+ || document_key.is_upgraded_office(){tracing::trace!("skipping non-document key");return Ok(());diff --git a/services/upload_extractor_lambda_handler/src/main.rs b/services/upload_extractor_lambda_handler/src/main.rsindex cc9233657b..32097d9ec3 100644--- a/services/upload_extractor_lambda_handler/src/main.rs+++ b/services/upload_extractor_lambda_handler/src/main.rs@@ -23,6 +23,7 @@ use model_entity::EntityType;use models_bulk_upload::{UploadDocumentStatus, UploadFolderStatus, UploadFolderStatusUpdate};use sha2::{Digest, Sha256};use sqs_client::upload_extractor::UploadExtractQueueMessage;+use std::ffi::OsStr;use std::path::Path;use std::{fs, str::FromStr};use std::{path::PathBuf, sync::Arc};@@ -99,8 +100,10 @@ async fn handler(Some(pid),);+ // A partial upload still has a usable tree; leaving it pending would hide+ // every folder because of one bad file.let (update_dynamodb_res, update_dss_res) = match &upload_status {- UploadFolderStatus::Completed => {+ UploadFolderStatus::Completed | UploadFolderStatus::PartiallyCompleted => {tokio::join!(update_dynamodb_fut,dss_client@@ -115,12 +118,21 @@ async fn handler(.inspect_err(|e| tracing::error!("Failed to update dynamo status: {:?}", e)).ok();- match update_dss_res {- Ok(_) => UploadFolderStatusUpdate::Completed {+ match (update_dss_res, &upload_status) {+ (Ok(_), UploadFolderStatus::Completed) => UploadFolderStatusUpdate::Completed {request_id: request_id.clone(),project_id: root_project_id.clone(),},- Err(e) => {+ (Ok(_), UploadFolderStatus::PartiallyCompleted) => {+ UploadFolderStatusUpdate::PartiallyCompleted {+ request_id: request_id.clone(),+ project_id: root_project_id.clone(),+ }+ }+ (Ok(_), _) => UploadFolderStatusUpdate::Failed {+ request_id: request_id.clone(),+ },+ (Err(e), _) => {tracing::error!("Failed to update dss status: {:?}", e);UploadFolderStatusUpdate::Unknown {request_id: request_id.clone(),@@ -250,14 +262,18 @@ async fn process_zipped_s3_object("Building file system structure for folder: {}",root_folder_name);- let folder_items = build_file_system(&extract_dir).await?;- tracing::debug!("Upload file system: {:?}", folder_items);+ let ExtractedTree {+ items: folder_items,+ folders,+ } = build_file_system(&extract_dir).await?;+ tracing::debug!("Upload file system: {:?} {:?}", folder_items, folders);let upload_result = dss_client.upload_unnested_folder(user_id.to_string(),root_folder_name,folder_items,+ folders,request_id.to_string(),parent_id.map(|s| s.to_string()),)@@ -489,27 +505,70 @@ fn extract_zip_file(Ok(root_dir_name)}-async fn build_file_system(extract_dir: &Path) -> Result<Vec<FolderItem>, Error> {- let mut tasks = Vec::new();+/// Files and folders collected from an extracted upload.+#[derive(Debug, Default)]+struct ExtractedTree {+ items: Vec<FolderItem>,+ /// Every kept folder, as a path relative to the extract dir, so empty+ /// folders still become projects.+ folders: Vec<String>,+}- // Walk the extracted directory and collect files- let walker = walkdir::WalkDir::new(extract_dir).into_iter();+/// OS and editor clutter that should never become a document or project.+fn is_ignored_name(name: &OsStr) -> bool {+ let name = name.to_string_lossy();+ let lower = name.to_ascii_lowercase();+ // Hidden files/folders, including `.DS_Store`, `._*` and `.~lock.*#`.+ name.starts_with('.')+ || name == "__MACOSX"+ // Office owner/lock files written next to open documents.+ || name.starts_with("~$")+ || lower == "thumbs.db"+ || lower == "ehthumbs.db"+ || lower == "desktop.ini"+ // macOS custom folder icon file.+ || name == "Icon\r"+}++/// Whether a path under the extract dir should be skipped. The first component+/// is the root folder the user picked, which is kept whatever its name.+fn is_ignored_entry(relative_path: &Path) -> bool {+ relative_path.iter().skip(1).any(is_ignored_name)+}++async fn build_file_system(extract_dir: &Path) -> Result<ExtractedTree, Error> {+ let mut tasks = Vec::new();+ let mut folders = Vec::new();++ let walker = walkdir::WalkDir::new(extract_dir)+ .min_depth(1)+ .sort_by_file_name()+ .into_iter()+ // Pruning here also skips everything inside an ignored folder.+ .filter_entry(|entry| {+ entry+ .path()+ .strip_prefix(extract_dir)+ .map(|relative| !is_ignored_entry(relative))+ .unwrap_or(false)+ });for entry in walker.filter_map(|e| e.ok()) {let path = entry.path().to_path_buf();-- // Skip directories and the root directory itself- if path.is_dir() || path == extract_dir || !root_dir_common_filter(path.as_path()) {+ let relative = path+ .strip_prefix(extract_dir)+ .map_err(|e| Error::from(format!("strip_prefix failed: {:?}", e)))?+ .to_path_buf();++ if entry.file_type().is_dir() {+ let folder = relative+ .to_str()+ .ok_or_else(|| Error::from(format!("Invalid folder name: {:?}", relative)))?;+ folders.push(folder.to_string());continue;}- // Skip hidden files and folders (names starting with '.')- if path- .file_name()- .and_then(|name| name.to_str())- .map(|name| name.starts_with('.'))- .unwrap_or(false)- {+ if !entry.file_type().is_file() {continue;}@@ -527,9 +586,7 @@ async fn build_file_system(extract_dir: &Path) -> Result<Vec<FolderItem>, Error>None => (full_name, None),};- let relative_path_without_filename = path- .strip_prefix(extract_dir)- .map_err(|e| Error::from(format!("strip_prefix failed: {:?}", e)))?+ let relative_path_without_filename = relative.parent().ok_or_else(|| Error::from(format!("No parent for path: {:?}", path)))?.to_string_lossy()@@ -537,7 +594,7 @@ async fn build_file_system(extract_dir: &Path) -> Result<Vec<FolderItem>, Error>let sha = compute_sha256(&path).await?;- Ok(FolderItem {+ Ok::<_, Error>(FolderItem {name: file_name.to_string(),full_name: full_name.to_string(),file_type,@@ -550,7 +607,8 @@ async fn build_file_system(extract_dir: &Path) -> Result<Vec<FolderItem>, Error>}// exits immediately if any task fails- try_join_all(tasks).await+ let items = try_join_all(tasks).await?;+ Ok(ExtractedTree { items, folders })}async fn compute_sha256(path: &Path) -> Result<String, Error> {@@ -567,15 +625,10 @@ async fn compute_sha256(path: &Path) -> Result<String, Error> {Ok(format!("{:x}", result)) // hex string}+/// `full_name` is the name on disk; rebuilding it from the parsed type would+/// lowercase extensions like `.DOCX` and miss the file.fn get_file_path_for_item(extract_dir: &Path, item: &FolderItem) -> PathBuf {- match &item.file_type {- None => extract_dir.join(&item.relative_path).join(&item.name),- Some(ext) => {- // TODO: use with added extension once stable- let full_name = format!("{}.{}", item.name, ext.as_str());- extract_dir.join(&item.relative_path).join(full_name)- }- }+ extract_dir.join(&item.relative_path).join(&item.full_name)}#[tokio::main]@@ -669,7 +722,7 @@ mod tests {nested_file.write_all(b"nested file content").unwrap();// Run the build_file_system function- let result = build_file_system(extract_dir).await.unwrap();+ let result = build_file_system(extract_dir).await.unwrap().items;// Verify the resultsassert_eq!(result.len(), 3); // Should have 3 files total@@ -785,10 +838,12 @@ mod tests {let extract_dir = temp_dir.path();// Run the build_file_system function- let result = build_file_system(extract_dir).await.unwrap();+ let result = build_file_system(extract_dir).await.unwrap().items;// Verify the resultsassert_eq!(result.len(), 0); // Should be empty+ let tree = build_file_system(extract_dir).await.unwrap();+ assert!(tree.folders.is_empty());}#[tokio::test]@@ -797,18 +852,21 @@ mod tests {let temp_dir = tempdir().unwrap();let extract_dir = temp_dir.path();+ let root_dir = extract_dir.join("root");+ fs::create_dir_all(&root_dir).unwrap();+// Create a visible file- let visible_file_path = extract_dir.join("visible.txt");+ let visible_file_path = root_dir.join("visible.txt");let mut visible_file = File::create(&visible_file_path).unwrap();visible_file.write_all(b"visible content").unwrap();// Create a hidden file- let hidden_file_path = extract_dir.join(".hidden.txt");+ let hidden_file_path = root_dir.join(".hidden.txt");let mut hidden_file = File::create(&hidden_file_path).unwrap();hidden_file.write_all(b"hidden content").unwrap();// Run the build_file_system function- let result = build_file_system(extract_dir).await.unwrap();+ let result = build_file_system(extract_dir).await.unwrap().items;// Verify that only the visible file is includedassert_eq!(result.len(), 1);@@ -828,7 +886,7 @@ mod tests {file.write_all(b"content without extension").unwrap();// Run the build_file_system function- let result = build_file_system(extract_dir).await.unwrap();+ let result = build_file_system(extract_dir).await.unwrap().items;// Verify the resultsassert_eq!(result.len(), 1);@@ -854,10 +912,202 @@ mod tests {let expected_sha = format!("{:x}", hasher.finalize());// Run the build_file_system function- let result = build_file_system(extract_dir).await.unwrap();+ let result = build_file_system(extract_dir).await.unwrap().items;// Verify the SHA256 hashassert_eq!(result.len(), 1);assert_eq!(result[0].sha, expected_sha);}++ #[test]+ fn test_get_file_path_for_item_keeps_extension_case() {+ let extract_dir = PathBuf::from("/tmp/extract");+ let item = FolderItem {+ name: "REPORT".to_string(),+ full_name: "REPORT.DOCX".to_string(),+ file_type: Some(FileType::Docx),+ relative_path: "Root".to_string(),+ sha: "abcd".to_string(),+ };++ assert_eq!(+ get_file_path_for_item(&extract_dir, &item),+ PathBuf::from("/tmp/extract/Root/REPORT.DOCX")+ );+ }++ #[test]+ fn test_is_ignored_entry() {+ for ignored in [+ "Root/.DS_Store",+ "Root/~$Summary.docx",+ "Root/Sub/~$Deck.pptx",+ "Root/Thumbs.db",+ "Root/THUMBS.DB",+ "Root/desktop.ini",+ "Root/Desktop.ini",+ "Root/ehthumbs.db",+ "Root/Icon\r",+ "Root/.git/config",+ "Root/__MACOSX/._a.docx",+ "Root/Sub/.~lock.Budget.xlsx#",+ ] {+ assert!(is_ignored_entry(Path::new(ignored)), "{ignored}");+ }+ for kept in [+ "Root",+ ".dotted-root",+ ".dotted-root/a.docx",+ "Root/a.docx",+ "Root/Sub/b.pptx",+ "Root/Thumbs.db.xlsx",+ "Root/report~$.docx",+ "Root/Icon.png",+ ] {+ assert!(!is_ignored_entry(Path::new(kept)), "{kept}");+ }+ }++ /// Zip entries as the web app's zip worker writes them for a dropped folder.+ fn write_browser_zip(path: &Path, entries: &[(&str, Option<&[u8]>)]) {+ let file = File::create(path).unwrap();+ let mut zip = zip::ZipWriter::new(file);+ let options = zip::write::SimpleFileOptions::default();+ for (name, contents) in entries {+ match contents {+ Some(bytes) => {+ zip.start_file(*name, options).unwrap();+ zip.write_all(bytes).unwrap();+ }+ None => zip.add_directory(*name, options).unwrap(),+ }+ }+ zip.finish().unwrap();+ }++ async fn extract_tree(+ entries: &[(&str, Option<&[u8]>)],+ zip_name: &str,+ ) -> (String, ExtractedTree, PathBuf, tempfile::TempDir) {+ let temp_dir = tempdir().unwrap();+ let zip_path = temp_dir.path().join("upload.zip");+ write_browser_zip(&zip_path, entries);+ let extract_dir = temp_dir.path().join("extracted");+ fs::create_dir_all(&extract_dir).unwrap();+ let root = extract_zip_file(&zip_path, &extract_dir, Some(zip_name)).unwrap();+ let tree = build_file_system(&extract_dir).await.unwrap();+ (root, tree, extract_dir, temp_dir)+ }++ #[tokio::test]+ async fn test_nested_office_folder_upload() {+ let entries: &[(&str, Option<&[u8]>)] = &[+ ("Board Pack/", None),+ ("Board Pack/Summary.docx", Some(b"docx")),+ ("Board Pack/REPORT UPPER.DOCX", Some(b"upper")),+ ("Board Pack/Deck.PPTX", Some(b"upper pptx")),+ ("Board Pack/Café Menü.docx", Some(b"unicode")),+ ("Board Pack/~$Summary.docx", Some(b"lock")),+ ("Board Pack/.DS_Store", Some(b"ds")),+ ("Board Pack/Thumbs.db", Some(b"thumbs")),+ ("Board Pack/desktop.ini", Some(b"ini")),+ ("Board Pack/.git/", None),+ ("Board Pack/.git/config", Some(b"git")),+ ("Board Pack/Empty Folder/", None),+ ("Board Pack/Finance/", None),+ ("Board Pack/Finance/Budget.xlsx", Some(b"xlsx")),+ ("Board Pack/Finance/Forecasts/", None),+ ("Board Pack/Finance/Forecasts/Scenarios/", None),+ (+ "Board Pack/Finance/Forecasts/Scenarios/Downside.xlsx",+ Some(b"xlsx2"),+ ),+ ("Board Pack/Finance/Forecasts/Scenarios/Empty Leaf/", None),+ ("Board Pack/Decks/", None),+ ("Board Pack/Decks/Archive/", None),+ ("Board Pack/Decks/Archive/Old.pptx", Some(b"pptx")),+ ("Board Pack/Decks/Archive/~$Old.pptx", Some(b"lock")),+ ];+ let (root, tree, extract_dir, _guard) = extract_tree(entries, "Board Pack").await;+ assert_eq!(root, "Board Pack");++ let mut files: Vec<String> = tree+ .items+ .iter()+ .map(|item| format!("{}/{}", item.relative_path, item.full_name))+ .collect();+ files.sort();+ assert_eq!(+ files,+ vec![+ "Board Pack/Café Menü.docx",+ "Board Pack/Deck.PPTX",+ "Board Pack/Decks/Archive/Old.pptx",+ "Board Pack/Finance/Budget.xlsx",+ "Board Pack/Finance/Forecasts/Scenarios/Downside.xlsx",+ "Board Pack/REPORT UPPER.DOCX",+ "Board Pack/Summary.docx",+ ]+ );++ // Every kept file must be found again when it is copied to storage.+ for item in &tree.items {+ assert!(+ get_file_path_for_item(&extract_dir, item).is_file(),+ "{item:?}"+ );+ }+ let upper = tree+ .items+ .iter()+ .find(|item| item.full_name == "REPORT UPPER.DOCX")+ .unwrap();+ assert_eq!(upper.file_type, Some(FileType::Docx));+ assert_eq!(upper.name, "REPORT UPPER");+ let deck = tree+ .items+ .iter()+ .find(|item| item.full_name == "Deck.PPTX")+ .unwrap();+ assert_eq!(deck.file_type, Some(FileType::Pptx));++ assert_eq!(+ tree.folders,+ vec![+ "Board Pack",+ "Board Pack/Decks",+ "Board Pack/Decks/Archive",+ "Board Pack/Empty Folder",+ "Board Pack/Finance",+ "Board Pack/Finance/Forecasts",+ "Board Pack/Finance/Forecasts/Scenarios",+ "Board Pack/Finance/Forecasts/Scenarios/Empty Leaf",+ ]+ );+ }++ #[tokio::test]+ async fn test_folder_with_only_empty_subfolders() {+ let entries: &[(&str, Option<&[u8]>)] =+ &[("Shell/", None), ("Shell/A/", None), ("Shell/A/B/", None)];+ let (root, tree, _extract_dir, _guard) = extract_tree(entries, "Shell").await;+ assert_eq!(root, "Shell");+ assert!(tree.items.is_empty());+ assert_eq!(tree.folders, vec!["Shell", "Shell/A", "Shell/A/B"]);+ }++ #[tokio::test]+ async fn test_single_subfolder_keeps_picked_root() {+ // The picked folder holds one subfolder and no files of its own.+ let entries: &[(&str, Option<&[u8]>)] = &[+ ("Wrapper/", None),+ ("Wrapper/Inner/", None),+ ("Wrapper/Inner/a.docx", Some(b"a")),+ ];+ let (root, tree, _extract_dir, _guard) = extract_tree(entries, "Wrapper").await;+ assert_eq!(root, "Wrapper");+ assert_eq!(tree.items.len(), 1);+ assert_eq!(tree.items[0].relative_path, "Wrapper/Inner");+ assert_eq!(tree.folders, vec!["Wrapper", "Wrapper/Inner"]);+ }}