53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { pathToFileURL } from 'node:url'
|
|
import { Context } from '@deepseek-ai/cordis'
|
|
import Include from '@deepseek-ai/cordis-plugin-include'
|
|
import Loader from '@deepseek-ai/cordis-plugin-loader'
|
|
import LocalTaskService from '@deepseek-ai/dsh-tasks-local'
|
|
|
|
let root: string | undefined
|
|
let context: Context | undefined
|
|
|
|
afterEach(async () => {
|
|
await context?.fiber.dispose()
|
|
context = undefined
|
|
if (root !== undefined) await rm(root, { recursive: true, force: true })
|
|
root = undefined
|
|
})
|
|
|
|
describe('tasks-local through a real Loader composition', () => {
|
|
it('applies the provider-owned admission config from a Cordis row', async () => {
|
|
root = await mkdtemp(join(tmpdir(), 'dsh-tasks-local-loader-'))
|
|
const configPath = join(root, 'cordis.yml')
|
|
await writeFile(configPath, [
|
|
"- name: '@deepseek-ai/dsh-tasks-local'",
|
|
' config:',
|
|
' maxConcurrentTasksPerOwner: 2',
|
|
'',
|
|
].join('\n'))
|
|
|
|
context = new Context()
|
|
context.baseUrl = pathToFileURL(root).href + '/'
|
|
await context.plugin(Loader)
|
|
context.loader.builtins.include = Include
|
|
context.loader.internal = {
|
|
version: 'v2',
|
|
async import(specifier: string) {
|
|
if (specifier === '@deepseek-ai/dsh-tasks-local') return LocalTaskService
|
|
throw new Error(`unexpected Loader import: ${specifier}`)
|
|
},
|
|
} as unknown as NonNullable<typeof context.loader.internal>
|
|
await context.loader.create({
|
|
name: 'cordis:include',
|
|
config: { path: pathToFileURL(configPath).href },
|
|
})
|
|
await context.loader.await()
|
|
|
|
expect(context.tasks).toBeInstanceOf(LocalTaskService)
|
|
expect((context.tasks as LocalTaskService).config.maxConcurrentTasksPerOwner).toBe(2)
|
|
})
|
|
})
|