feat(skills): enable watcher wiring through daemon lifecycle

This commit is contained in:
William Valentin
2026-02-12 17:18:22 -08:00
parent 95091cc198
commit b773e2bbf3
6 changed files with 171 additions and 9 deletions
+57
View File
@@ -0,0 +1,57 @@
import { afterEach, describe, expect, it } from 'vitest';
import { mkdtempSync, mkdirSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
import { configSchema } from '../config/schema.js';
import { Lifecycle } from './lifecycle.js';
import { initSkills } from './services.js';
describe('initSkills watcher wiring', () => {
const roots: string[] = [];
afterEach(() => {
for (const root of roots.splice(0)) {
rmSync(root, { recursive: true, force: true });
}
});
function makeConfig(overrides: Record<string, unknown> = {}) {
return configSchema.parse({
telegram: { bot_token: 'test-token', allowed_chat_ids: [1] },
models: { default: { provider: 'anthropic', model: 'claude-3' } },
...overrides,
});
}
it('does not create a watcher when disabled', () => {
const config = makeConfig();
const lifecycle = new Lifecycle();
const result = initSkills(config, lifecycle);
expect(result.skillsWatcher).toBeUndefined();
});
it('starts watcher and stops it on lifecycle shutdown when enabled', async () => {
const root = mkdtempSync(join(tmpdir(), 'flynn-services-'));
roots.push(root);
const managedDir = join(root, 'skills');
mkdirSync(managedDir, { recursive: true });
const config = makeConfig({
skills: {
managed_dir: managedDir,
load: { watch: true, watch_debounce_ms: 100 },
},
});
const lifecycle = new Lifecycle();
const result = initSkills(config, lifecycle);
expect(result.skillsWatcher?.isRunning).toBe(true);
expect(result.skillsWatcher?.watchedDirectoryCount).toBe(1);
await lifecycle.shutdown();
expect(result.skillsWatcher?.isRunning).toBe(false);
});
});