import { mkdtemp, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { afterAll, beforeAll, describe, expect, test } from 'bun:test'; import { runWithPlugins } from '../../../src/plugins/pluginRunner.js'; import { _resetPluginCache } from '../../../src/plugins/commandRouter.js'; import { _resetPluginLoader } from '../../../src/plugins/pluginLoader.js'; import type { Message, Provider } from '../../../src/types.js'; let root = ''; const provider: Provider = { name: 'test', baseURL: 'https://example.invalid', apiKey: 'test', model: 'test-model', contextWindow: 128000, }; describe('cron-runner plugin integration', () => { beforeAll(async () => { root = await mkdtemp(join(tmpdir(), 'cron-runner-integration-')); process.env.MINIMAL_AGENT_CRON_RUNNER_HOME = root; _resetPluginCache(); _resetPluginLoader(); }); afterAll(async () => { delete process.env.MINIMAL_AGENT_CRON_RUNNER_HOME; _resetPluginCache(); _resetPluginLoader(); if (root) await rm(root, { recursive: true, force: true }); }); test('/cron command is handled by cron-runner plugin', async () => { const history: Message[] = [{ role: 'system', content: 'test' }]; let text = ''; for await (const ev of runWithPlugins( '/cron create --name "Daily" --cron "7 6 * * *" --prompt "hello" --fresh-session', { provider, history, runtimeContext: { surface: 'tui', profile: 'main', owner: 'local-owner', cwd: root, sessionId: 'integration-session', memoryAccess: 'denied', interactiveAsk: true } }, )) { if (ev.type === 'text') text += ev.delta; } expect(text).toContain('已创建 cron'); expect(text).toContain('Daily'); }); });