Skip to content

Commit c2e7796

Browse files
committed
fix(knowledge): audit an import as started, and drop the mock-only dispatch test
- the completion records knowledge_base.import_started; the base exists only once the runner creates it - background-task.test.ts only checked forwarded mock arguments; the delete-async route test and the integration suite exercise the helper's real paths
1 parent 620d9f6 commit c2e7796

6 files changed

Lines changed: 9 additions & 73 deletions

File tree

‎apps/docs/content/docs/knowledgebase/export-import.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ A document the archive carries only as chunks, such as one from a [connector](/k
8686

8787
Archives must be `.zip` files of at most **5 GiB**, and every document file at most **100 MB**. The archive is validated before anything is created, so a damaged or modified archive fails without leaving a partial base. Imports count toward storage and usage limits like uploads do.
8888

89-
Canceling stops after the document in progress. Documents already imported stay in the new base. Each completed import upload records an audit event.
89+
Canceling stops after the document in progress. Documents already imported stay in the new base. Starting an import records one audit event, naming the knowledge base it creates.
9090

9191
## Archive contents
9292

‎apps/sim/lib/core/async-jobs/background-task.test.ts‎

Lines changed: 0 additions & 65 deletions
This file was deleted.

‎apps/sim/lib/knowledge/__integration__/bundle-import.integration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ describe('knowledge base import requests', () => {
600600
.where(
601601
and(
602602
eq(auditLog.workspaceId, ids.workspaceId),
603-
eq(auditLog.action, 'knowledge_base.imported')
603+
eq(auditLog.action, 'knowledge_base.import_started')
604604
)
605605
)
606606
)

‎apps/sim/lib/knowledge/application/imports.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,16 @@ export const completeKnowledgeImport = defineAuthorizedKnowledgeUseCase({
420420
return { import: fromRecord(record) }
421421
},
422422
/**
423-
* Keyed by the import, so the completion that started it and any retry of it
424-
* record one event between them. The base takes the import's id.
423+
* What the caller did is start the import: the base exists only once the
424+
* runner creates it, under the import's id. Keyed by the import, so the
425+
* completion that started it and any retry of it record one event between them.
425426
*/
426427
projectAudit: ({ context, result }) => ({
427-
action: AuditAction.KNOWLEDGE_BASE_IMPORTED,
428+
action: AuditAction.KNOWLEDGE_BASE_IMPORT_STARTED,
428429
resourceType: AuditResourceType.KNOWLEDGE_BASE,
429430
resourceId: result.import.id,
430431
resourceName: importedName(context.upload) ?? context.upload.fileName,
431-
description: `Imported a knowledge base from bundle "${context.upload.fileName}"`,
432+
description: `Started importing a knowledge base from bundle "${context.upload.fileName}"`,
432433
metadata: { workspaceId: context.workspaceId, importId: result.import.id },
433434
idempotencyKey: `knowledge-import:${result.import.id}`,
434435
}),

‎packages/audit/src/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const AuditAction = {
130130
KNOWLEDGE_BASE_DELETED: 'knowledge_base.deleted',
131131
KNOWLEDGE_BASE_RESTORED: 'knowledge_base.restored',
132132
KNOWLEDGE_BASE_EXPORTED: 'knowledge_base.exported',
133-
KNOWLEDGE_BASE_IMPORTED: 'knowledge_base.imported',
133+
KNOWLEDGE_BASE_IMPORT_STARTED: 'knowledge_base.import_started',
134134

135135
MCP_SERVER_ADDED: 'mcp_server.added',
136136
MCP_SERVER_UPDATED: 'mcp_server.updated',

‎packages/testing/src/mocks/audit.mock.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const AuditAction = {
102102
KNOWLEDGE_BASE_DELETED: 'knowledge_base.deleted',
103103
KNOWLEDGE_BASE_RESTORED: 'knowledge_base.restored',
104104
KNOWLEDGE_BASE_EXPORTED: 'knowledge_base.exported',
105-
KNOWLEDGE_BASE_IMPORTED: 'knowledge_base.imported',
105+
KNOWLEDGE_BASE_IMPORT_STARTED: 'knowledge_base.import_started',
106106
MCP_SERVER_ADDED: 'mcp_server.added',
107107
MCP_SERVER_UPDATED: 'mcp_server.updated',
108108
MCP_SERVER_REMOVED: 'mcp_server.removed',

0 commit comments

Comments
 (0)