Files
Ncurator/tests/case/knowledge/foundation/prepare-workspaces-sequentially.test.ts
hy 403848569f Refactor knowledge test plans and unit tests for workspace indexing
- Updated knowledge test plans to clarify the cancellation behavior of workspace indexing and its interaction with the backend.
- Revised assertions in the `workspace-index-cancel-contract` test to ensure completed entries are preserved and unfinished entries are reverted correctly.
- Enhanced the `prepare-workspaces-sequentially` test to validate that subsequent addresses do not start after the first is cancelled.
- Removed obsolete `cnipa-http.host.test.ts` and `electronBareNavigateHost.mjs` files as they are no longer needed.
- Added new assertions in the `workspace-index-job-progress.test.ts` to verify the handling of completed and unfinished job states.
- Improved the `workspace-index-worker-contract.test.ts` to ensure proper cancellation behavior during embedding processes.
- Updated E2E tests for right panel layout and tab interactions to include resizing functionality.
2026-10-14 18:01:13 +08:00

69 lines
2.8 KiB
TypeScript

import { mkdir, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { describe, it } from 'vitest'
import { WorkspaceKnowledgePrepareService } from '../../../../src/main/services/workspace/WorkspaceKnowledgePrepareService'
import { prepareWorkspaceSource } from '../../../../src/main/services/workspace/worker/workspacePrepareWorker'
import { prepareWorkspacesSequentially } from '../../../../src/shared/prepareWorkspacesSequentially'
import { runBackendCase } from '../../../harness/backend/run-backend-case'
describe('knowledge foundation', () => {
it('prepare-workspaces-sequentially', async () => {
await runBackendCase({
caseId: 'prepare-workspaces-sequentially',
harnessMode: 'tool-real',
domain: 'knowledge',
suite: 'foundation',
description: '多地址更新索引按顺序等待前一个完成再启动下一个。',
fixtures: [],
runMode: 'single',
execute: async (runtime) => {
await runtime.prepareEmbeddingModel()
const prepareService = new WorkspaceKnowledgePrepareService({
embeddingService: runtime.embeddingService,
documentsStore: runtime.documentsStore,
prepareSource: prepareWorkspaceSource
})
const workspaceIds = ['ws-a', 'ws-b', 'ws-c']
const now = Date.now()
for (const workspaceId of workspaceIds) {
const rootPath = path.join(runtime.workspaceRoot, workspaceId)
await mkdir(rootPath, { recursive: true })
await writeFile(path.join(rootPath, 'note.txt'), `${workspaceId} sequential index\n`)
await runtime.storageService.workspace.saveWorkspace({
id: workspaceId,
root_path: rootPath,
created_at: now,
updated_at: now
})
}
const events: string[] = []
const results = await prepareWorkspacesSequentially(workspaceIds, async (workspaceId) => {
events.push(`start:${workspaceId}`)
const indexed = await prepareService.indexLocalFile({
workspaceId,
documentId: `${workspaceId}-doc`,
filePath: path.join(runtime.workspaceRoot, workspaceId, 'note.txt'),
documentName: 'note.txt'
})
events.push(`end:${workspaceId}`)
return indexed.documentId
})
return { results, events }
},
assert: async (result, runtime) => {
runtime.assertThat(
result.results.join(',') === 'ws-a-doc,ws-b-doc,ws-c-doc' &&
result.events.join(',') ===
'start:ws-a,end:ws-a,start:ws-b,end:ws-b,start:ws-c,end:ws-c',
{
name: 'prepare-is-sequential',
message: '多地址更新索引必须等前一个完成后再启动下一个,对齐 SET-WORKSPACE-004-AC11。',
data: result
}
)
}
})
})
})